|
| 1 | +import { createRuleTester } from '../test-utils'; |
| 2 | +import rule, { RULE_NAME } from '../../../lib/rules/no-wait-for-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 | + import { ${asyncUtil} } from '@testing-library/dom'; |
| 21 | + test('snapshot calls outside of ${asyncUtil} are valid', () => { |
| 22 | + expect(foo).toMatchSnapshot() |
| 23 | + await ${asyncUtil}(() => { |
| 24 | + expect(foo).toBeDefined() |
| 25 | + }) |
| 26 | + expect(foo).toMatchSnapshot() |
| 27 | + }) |
| 28 | + `, |
| 29 | + })), |
| 30 | + ...ASYNC_UTILS.map(asyncUtil => ({ |
| 31 | + code: ` |
| 32 | + import { ${asyncUtil} } from 'a-different-library'; |
| 33 | + test('snapshot calls within ${asyncUtil} are not valid', async () => { |
| 34 | + await ${asyncUtil}(() => expect(foo).toMatchSnapshot()); |
| 35 | + }); |
| 36 | + `, |
| 37 | + })), |
| 38 | + ...ASYNC_UTILS.map(asyncUtil => ({ |
| 39 | + code: ` |
| 40 | + import { ${asyncUtil} } from 'a-different-library'; |
| 41 | + test('snapshot calls within ${asyncUtil} are not valid', async () => { |
| 42 | + await ${asyncUtil}(() => { |
| 43 | + expect(foo).toMatchSnapshot() |
| 44 | + }); |
| 45 | + }); |
| 46 | + `, |
| 47 | + })), |
| 48 | + ], |
| 49 | + invalid: [ |
| 50 | + ...ASYNC_UTILS.map(asyncUtil => ({ |
| 51 | + code: ` |
| 52 | + import { ${asyncUtil} } from '@testing-library/dom'; |
| 53 | + test('snapshot calls within ${asyncUtil} are not valid', async () => { |
| 54 | + await ${asyncUtil}(() => expect(foo).toMatchSnapshot()); |
| 55 | + }); |
| 56 | + `, |
| 57 | + errors: [{ line: 4, messageId: 'noWaitForSnapshot' }], |
| 58 | + })), |
| 59 | + ...ASYNC_UTILS.map(asyncUtil => ({ |
| 60 | + code: ` |
| 61 | + import { ${asyncUtil} } from '@testing-library/dom'; |
| 62 | + test('snapshot calls within ${asyncUtil} are not valid', async () => { |
| 63 | + await ${asyncUtil}(() => { |
| 64 | + expect(foo).toMatchSnapshot() |
| 65 | + }); |
| 66 | + }); |
| 67 | + `, |
| 68 | + errors: [{ line: 5, messageId: 'noWaitForSnapshot' }], |
| 69 | + })), |
| 70 | + ], |
| 71 | +}); |
0 commit comments