|  | 
|  | 1 | +import { createRuleTester } from '../test-utils'; | 
|  | 2 | +import rule, { RULE_NAME } from '../../../lib/rules/no-wait-snapshot'; | 
|  | 3 | +import { ASYNC_UTILS } from '../../../lib/utils'; | 
|  | 4 | + | 
|  | 5 | +const ruleTester = createRuleTester(); | 
|  | 6 | + | 
|  | 7 | +ruleTester.run(RULE_NAME, rule, { | 
|  | 8 | +  valid: [ | 
|  | 9 | +    ...ASYNC_UTILS.map(asyncUtil => ({ | 
|  | 10 | +      code: ` | 
|  | 11 | +        test('snapshot calls outside of ${asyncUtil} are valid', () => { | 
|  | 12 | +          expect(foo).toMatchSnapshot() | 
|  | 13 | +          await ${asyncUtil}(() => expect(foo).toBeDefined()) | 
|  | 14 | +          expect(foo).toMatchSnapshot() | 
|  | 15 | +        }) | 
|  | 16 | +      `, | 
|  | 17 | +    })), | 
|  | 18 | +    ...ASYNC_UTILS.map(asyncUtil => ({ | 
|  | 19 | +      code: ` | 
|  | 20 | +        test('snapshot calls outside of ${asyncUtil} are valid', () => { | 
|  | 21 | +          expect(foo).toMatchSnapshot() | 
|  | 22 | +          await ${asyncUtil}(() => { | 
|  | 23 | +              expect(foo).toBeDefined() | 
|  | 24 | +          }) | 
|  | 25 | +          expect(foo).toMatchSnapshot() | 
|  | 26 | +        }) | 
|  | 27 | +      `, | 
|  | 28 | +    })), | 
|  | 29 | +  ], | 
|  | 30 | +  invalid: [ | 
|  | 31 | +    ...ASYNC_UTILS.map(asyncUtil => ({ | 
|  | 32 | +      code: ` | 
|  | 33 | +        import { ${asyncUtil} } from '@testing-library/dom'; | 
|  | 34 | +        test('snapshot calls within ${asyncUtil} are not valid', async () => { | 
|  | 35 | +          await ${asyncUtil}(() => expect(foo).toMatchSnapshot()); | 
|  | 36 | +        }); | 
|  | 37 | +      `, | 
|  | 38 | +      errors: [{ line: 4, messageId: 'noWaitSnapshot' }], | 
|  | 39 | +    })), | 
|  | 40 | +    ...ASYNC_UTILS.map(asyncUtil => ({ | 
|  | 41 | +      code: ` | 
|  | 42 | +        import { ${asyncUtil} } from '@testing-library/dom'; | 
|  | 43 | +        test('snapshot calls within ${asyncUtil} are not valid', async () => { | 
|  | 44 | +          await ${asyncUtil}(() => { | 
|  | 45 | +              expect(foo).toMatchSnapshot() | 
|  | 46 | +          }); | 
|  | 47 | +        }); | 
|  | 48 | +      `, | 
|  | 49 | +      errors: [{ line: 5, messageId: 'noWaitSnapshot' }], | 
|  | 50 | +    })), | 
|  | 51 | +  ], | 
|  | 52 | +}); | 
0 commit comments