|
| 1 | +import { TSESLint } from '@typescript-eslint/experimental-utils'; |
| 2 | +import dedent from 'dedent'; |
| 3 | +import resolveFrom from 'resolve-from'; |
| 4 | +import rule from '../no-unhooked-function-calls'; |
| 5 | + |
| 6 | +const ruleTester = new TSESLint.RuleTester({ |
| 7 | + parser: resolveFrom(require.resolve('eslint'), 'espree'), |
| 8 | + parserOptions: { |
| 9 | + ecmaVersion: 2017, |
| 10 | + }, |
| 11 | +}); |
| 12 | + |
| 13 | +ruleTester.run('no-unhooked-function-calls', rule, { |
| 14 | + valid: [ |
| 15 | + dedent` |
| 16 | + test('it', () => { |
| 17 | + // |
| 18 | + }); |
| 19 | + `, |
| 20 | + dedent` |
| 21 | + describe('some tests', () => { |
| 22 | + it('is true', () => { |
| 23 | + expect(true).toBe(true); |
| 24 | + }); |
| 25 | + }); |
| 26 | + `, |
| 27 | + dedent` |
| 28 | + describe('some tests', () => { |
| 29 | + it('is true', () => { |
| 30 | + expect(true).toBe(true); |
| 31 | + }); |
| 32 | +
|
| 33 | + describe('more tests', () => { |
| 34 | + it('is false', () => { |
| 35 | + expect(true).toBe(false); |
| 36 | + }); |
| 37 | + }); |
| 38 | + }); |
| 39 | + `, |
| 40 | + dedent` |
| 41 | + describe('some tests', () => { |
| 42 | + let consoleLogSpy; |
| 43 | +
|
| 44 | + beforeEach(() => { |
| 45 | + consoleLogSpy = jest.spyOn(console, 'log'); |
| 46 | + }); |
| 47 | +
|
| 48 | + it('prints a message', () => { |
| 49 | + printMessage('hello world'); |
| 50 | +
|
| 51 | + expect(consoleLogSpy).toHaveBeenCalledWith('hello world'); |
| 52 | + }); |
| 53 | + }); |
| 54 | + `, |
| 55 | + dedent` |
| 56 | + describe('some tests', () => { |
| 57 | + beforeEach(() => { |
| 58 | + setup(); |
| 59 | + }); |
| 60 | + }); |
| 61 | + `, |
| 62 | + dedent` |
| 63 | + beforeEach(() => { |
| 64 | + initializeCityDatabase(); |
| 65 | + }); |
| 66 | +
|
| 67 | + afterEach(() => { |
| 68 | + clearCityDatabase(); |
| 69 | + }); |
| 70 | +
|
| 71 | + test('city database has Vienna', () => { |
| 72 | + expect(isCity('Vienna')).toBeTruthy(); |
| 73 | + }); |
| 74 | +
|
| 75 | + test('city database has San Juan', () => { |
| 76 | + expect(isCity('San Juan')).toBeTruthy(); |
| 77 | + }); |
| 78 | + `, |
| 79 | + dedent` |
| 80 | + describe('cities', () => { |
| 81 | + beforeEach(() => { |
| 82 | + initializeCityDatabase(); |
| 83 | + }); |
| 84 | +
|
| 85 | + test('city database has Vienna', () => { |
| 86 | + expect(isCity('Vienna')).toBeTruthy(); |
| 87 | + }); |
| 88 | +
|
| 89 | + test('city database has San Juan', () => { |
| 90 | + expect(isCity('San Juan')).toBeTruthy(); |
| 91 | + }); |
| 92 | +
|
| 93 | + afterEach(() => { |
| 94 | + clearCityDatabase(); |
| 95 | + }); |
| 96 | + }); |
| 97 | + `, |
| 98 | + ], |
| 99 | + invalid: [ |
| 100 | + { |
| 101 | + code: dedent` |
| 102 | + describe('some tests', () => { |
| 103 | + setup(); |
| 104 | + }); |
| 105 | + `, |
| 106 | + errors: [ |
| 107 | + { |
| 108 | + messageId: 'useHook', |
| 109 | + line: 2, |
| 110 | + column: 3, |
| 111 | + }, |
| 112 | + ], |
| 113 | + }, |
| 114 | + { |
| 115 | + code: dedent` |
| 116 | + describe('some tests', () => { |
| 117 | + setup(); |
| 118 | +
|
| 119 | + it('is true', () => { |
| 120 | + expect(true).toBe(true); |
| 121 | + }); |
| 122 | +
|
| 123 | + describe('more tests', () => { |
| 124 | + setup(); |
| 125 | +
|
| 126 | + it('is false', () => { |
| 127 | + expect(true).toBe(false); |
| 128 | + }); |
| 129 | + }); |
| 130 | + }); |
| 131 | + `, |
| 132 | + errors: [ |
| 133 | + { |
| 134 | + messageId: 'useHook', |
| 135 | + line: 2, |
| 136 | + column: 3, |
| 137 | + }, |
| 138 | + { |
| 139 | + messageId: 'useHook', |
| 140 | + line: 9, |
| 141 | + column: 5, |
| 142 | + }, |
| 143 | + ], |
| 144 | + }, |
| 145 | + ], |
| 146 | +}); |
0 commit comments