eslint-plugin-jest 27.2.0 → 27.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/docs/rules/no-alias-methods.md +1 -1
- package/docs/rules/no-hooks.md +1 -1
- package/docs/rules/no-if.md +1 -1
- package/docs/rules/no-large-snapshots.md +4 -0
- package/docs/rules/require-hook.md +2 -6
- package/docs/rules/valid-expect.md +2 -2
- package/lib/index.js +5 -12
- package/lib/processors/__tests__/snapshot-processor.test.js +36 -0
- package/lib/rules/__tests__/consistent-test-it.test.js +921 -0
- package/lib/rules/__tests__/expect-expect.test.js +347 -0
- package/lib/rules/__tests__/fixtures/class.ts +13 -0
- package/lib/rules/__tests__/fixtures/file.ts +0 -0
- package/lib/rules/__tests__/fixtures/foo.ts +1 -0
- package/lib/rules/__tests__/fixtures/indent/indent-invalid-fixture-1.js +530 -0
- package/lib/rules/__tests__/fixtures/indent/indent-valid-fixture-1.js +530 -0
- package/lib/rules/__tests__/fixtures/react.tsx +0 -0
- package/lib/rules/__tests__/fixtures/tsconfig-withmeta.json +6 -0
- package/lib/rules/__tests__/fixtures/tsconfig.json +16 -0
- package/lib/rules/__tests__/fixtures/unstrict/file.ts +0 -0
- package/lib/rules/__tests__/fixtures/unstrict/react.tsx +0 -0
- package/lib/rules/__tests__/fixtures/unstrict/tsconfig.json +15 -0
- package/lib/rules/__tests__/max-expects.test.js +330 -0
- package/lib/rules/__tests__/max-nested-describe.test.js +247 -0
- package/lib/rules/__tests__/no-alias-methods.test.js +190 -0
- package/lib/rules/__tests__/no-commented-out-tests.test.js +213 -0
- package/lib/rules/__tests__/no-conditional-expect.test.js +696 -0
- package/lib/rules/__tests__/no-conditional-in-test.test.js +777 -0
- package/lib/rules/__tests__/no-deprecated-functions.test.js +119 -0
- package/lib/rules/__tests__/no-disabled-tests.test.js +241 -0
- package/lib/rules/__tests__/no-done-callback.test.js +424 -0
- package/lib/rules/__tests__/no-duplicate-hooks.test.js +469 -0
- package/lib/rules/__tests__/no-export.test.js +107 -0
- package/lib/rules/__tests__/no-focused-tests.test.js +373 -0
- package/lib/rules/__tests__/no-hooks.test.js +90 -0
- package/lib/rules/__tests__/no-identical-title.test.js +270 -0
- package/lib/rules/__tests__/no-if.test.js +787 -0
- package/lib/rules/__tests__/no-interpolation-in-snapshots.test.js +58 -0
- package/lib/rules/__tests__/no-jasmine-globals.test.js +206 -0
- package/lib/rules/__tests__/no-large-snapshots.test.js +237 -0
- package/lib/rules/__tests__/no-mocks-import.test.js +73 -0
- package/lib/rules/__tests__/no-restricted-jest-methods.test.js +103 -0
- package/lib/rules/__tests__/no-restricted-matchers.test.js +244 -0
- package/lib/rules/__tests__/no-standalone-expect.test.js +230 -0
- package/lib/rules/__tests__/no-test-prefixes.test.js +206 -0
- package/lib/rules/__tests__/no-test-return-statement.test.js +122 -0
- package/lib/rules/__tests__/no-untyped-mock-factory.test.js +149 -0
- package/lib/rules/__tests__/prefer-called-with.test.js +40 -0
- package/lib/rules/__tests__/prefer-comparison-matcher.test.js +200 -0
- package/lib/rules/__tests__/prefer-each.test.js +295 -0
- package/lib/rules/__tests__/prefer-equality-matcher.test.js +184 -0
- package/lib/rules/__tests__/prefer-expect-assertions.test.js +1437 -0
- package/lib/rules/__tests__/prefer-expect-resolves.test.js +96 -0
- package/lib/rules/__tests__/prefer-hooks-in-order.test.js +678 -0
- package/lib/rules/__tests__/prefer-hooks-on-top.test.js +218 -0
- package/lib/rules/__tests__/prefer-lowercase-title.test.js +619 -0
- package/lib/rules/__tests__/prefer-mock-promise-shorthand.test.js +360 -0
- package/lib/rules/__tests__/prefer-snapshot-hint.test.js +784 -0
- package/lib/rules/__tests__/prefer-spy-on.test.js +100 -0
- package/lib/rules/__tests__/prefer-strict-equal.test.js +46 -0
- package/lib/rules/__tests__/prefer-to-be.test.js +438 -0
- package/lib/rules/__tests__/prefer-to-contain.test.js +301 -0
- package/lib/rules/__tests__/prefer-to-have-length.test.js +99 -0
- package/lib/rules/__tests__/prefer-todo.test.js +78 -0
- package/lib/rules/__tests__/require-hook.test.js +403 -0
- package/lib/rules/__tests__/require-to-throw-message.test.js +108 -0
- package/lib/rules/__tests__/require-top-level-describe.test.js +236 -0
- package/lib/rules/__tests__/test-utils.js +11 -0
- package/lib/rules/__tests__/unbound-method.test.js +518 -0
- package/lib/rules/__tests__/valid-describe-callback.test.js +305 -0
- package/lib/rules/__tests__/valid-expect-in-promise.test.js +1583 -0
- package/lib/rules/__tests__/valid-expect.test.js +894 -0
- package/lib/rules/__tests__/valid-title.test.js +1147 -0
- package/lib/rules/utils/__tests__/detectJestVersion.test.js +221 -0
- package/lib/rules/utils/__tests__/parseJestFnCall.test.js +809 -0
- package/lib/rules/utils/accessors.js +4 -0
- package/lib/rules/utils/misc.js +36 -20
- package/lib/rules/valid-expect-in-promise.js +3 -3
- package/package.json +13 -9
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _utils = require("@typescript-eslint/utils");
|
|
4
|
+
var _dedent = _interopRequireDefault(require("dedent"));
|
|
5
|
+
var _expectExpect = _interopRequireDefault(require("../expect-expect"));
|
|
6
|
+
var _testUtils = require("./test-utils");
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
const ruleTester = new _utils.TSESLint.RuleTester({
|
|
9
|
+
parser: _testUtils.espreeParser,
|
|
10
|
+
parserOptions: {
|
|
11
|
+
ecmaVersion: 2015
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
ruleTester.run('expect-expect', _expectExpect.default, {
|
|
15
|
+
valid: ['it.todo("will test something eventually")', 'test.todo("will test something eventually")', "['x']();", 'it("should pass", () => expect(true).toBeDefined())', 'test("should pass", () => expect(true).toBeDefined())', 'it("should pass", () => somePromise().then(() => expect(true).toBeDefined()))', 'it("should pass", myTest); function myTest() { expect(true).toBeDefined() }', {
|
|
16
|
+
code: (0, _dedent.default)`
|
|
17
|
+
test('should pass', () => {
|
|
18
|
+
expect(true).toBeDefined();
|
|
19
|
+
foo(true).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
`,
|
|
22
|
+
options: [{
|
|
23
|
+
assertFunctionNames: ['expect', 'foo']
|
|
24
|
+
}]
|
|
25
|
+
}, {
|
|
26
|
+
code: 'it("should return undefined",() => expectSaga(mySaga).returns());',
|
|
27
|
+
options: [{
|
|
28
|
+
assertFunctionNames: ['expectSaga']
|
|
29
|
+
}]
|
|
30
|
+
}, {
|
|
31
|
+
code: "test('verifies expect method call', () => expect$(123));",
|
|
32
|
+
options: [{
|
|
33
|
+
assertFunctionNames: ['expect\\$']
|
|
34
|
+
}]
|
|
35
|
+
}, {
|
|
36
|
+
code: "test('verifies expect method call', () => new Foo().expect(123));",
|
|
37
|
+
options: [{
|
|
38
|
+
assertFunctionNames: ['Foo.expect']
|
|
39
|
+
}]
|
|
40
|
+
}, {
|
|
41
|
+
code: (0, _dedent.default)`
|
|
42
|
+
test('verifies deep expect method call', () => {
|
|
43
|
+
tester.foo().expect(123);
|
|
44
|
+
});
|
|
45
|
+
`,
|
|
46
|
+
options: [{
|
|
47
|
+
assertFunctionNames: ['tester.foo.expect']
|
|
48
|
+
}]
|
|
49
|
+
}, {
|
|
50
|
+
code: (0, _dedent.default)`
|
|
51
|
+
test('verifies chained expect method call', () => {
|
|
52
|
+
tester
|
|
53
|
+
.foo()
|
|
54
|
+
.bar()
|
|
55
|
+
.expect(456);
|
|
56
|
+
});
|
|
57
|
+
`,
|
|
58
|
+
options: [{
|
|
59
|
+
assertFunctionNames: ['tester.foo.bar.expect']
|
|
60
|
+
}]
|
|
61
|
+
}, {
|
|
62
|
+
code: (0, _dedent.default)`
|
|
63
|
+
test("verifies the function call", () => {
|
|
64
|
+
td.verify(someFunctionCall())
|
|
65
|
+
})
|
|
66
|
+
`,
|
|
67
|
+
options: [{
|
|
68
|
+
assertFunctionNames: ['td.verify']
|
|
69
|
+
}]
|
|
70
|
+
}, {
|
|
71
|
+
code: 'it("should pass", () => expect(true).toBeDefined())',
|
|
72
|
+
options: [{
|
|
73
|
+
assertFunctionNames: undefined,
|
|
74
|
+
additionalTestBlockFunctions: undefined
|
|
75
|
+
}]
|
|
76
|
+
}, {
|
|
77
|
+
code: (0, _dedent.default)`
|
|
78
|
+
theoretically('the number {input} is correctly translated to string', theories, theory => {
|
|
79
|
+
const output = NumberToLongString(theory.input);
|
|
80
|
+
expect(output).toBe(theory.expected);
|
|
81
|
+
})
|
|
82
|
+
`,
|
|
83
|
+
options: [{
|
|
84
|
+
additionalTestBlockFunctions: ['theoretically']
|
|
85
|
+
}]
|
|
86
|
+
}],
|
|
87
|
+
invalid: [{
|
|
88
|
+
code: 'it("should fail", () => {});',
|
|
89
|
+
errors: [{
|
|
90
|
+
messageId: 'noAssertions',
|
|
91
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
92
|
+
}]
|
|
93
|
+
}, {
|
|
94
|
+
code: 'it("should fail", myTest); function myTest() {}',
|
|
95
|
+
errors: [{
|
|
96
|
+
messageId: 'noAssertions',
|
|
97
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
98
|
+
}]
|
|
99
|
+
}, {
|
|
100
|
+
code: 'test("should fail", () => {});',
|
|
101
|
+
errors: [{
|
|
102
|
+
messageId: 'noAssertions',
|
|
103
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
104
|
+
}]
|
|
105
|
+
}, {
|
|
106
|
+
code: 'test.skip("should fail", () => {});',
|
|
107
|
+
errors: [{
|
|
108
|
+
messageId: 'noAssertions',
|
|
109
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
110
|
+
}]
|
|
111
|
+
}, {
|
|
112
|
+
code: 'afterEach(() => {});',
|
|
113
|
+
options: [{
|
|
114
|
+
additionalTestBlockFunctions: ['afterEach']
|
|
115
|
+
}],
|
|
116
|
+
errors: [{
|
|
117
|
+
messageId: 'noAssertions',
|
|
118
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
119
|
+
}]
|
|
120
|
+
}, {
|
|
121
|
+
code: (0, _dedent.default)`
|
|
122
|
+
theoretically('the number {input} is correctly translated to string', theories, theory => {
|
|
123
|
+
const output = NumberToLongString(theory.input);
|
|
124
|
+
})
|
|
125
|
+
`,
|
|
126
|
+
options: [{
|
|
127
|
+
additionalTestBlockFunctions: ['theoretically']
|
|
128
|
+
}],
|
|
129
|
+
errors: [{
|
|
130
|
+
messageId: 'noAssertions',
|
|
131
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
132
|
+
}]
|
|
133
|
+
}, {
|
|
134
|
+
code: 'it("should fail", () => { somePromise.then(() => {}); });',
|
|
135
|
+
errors: [{
|
|
136
|
+
messageId: 'noAssertions',
|
|
137
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
138
|
+
}]
|
|
139
|
+
}, {
|
|
140
|
+
code: 'test("should fail", () => { foo(true).toBe(true); })',
|
|
141
|
+
options: [{
|
|
142
|
+
assertFunctionNames: ['expect']
|
|
143
|
+
}],
|
|
144
|
+
errors: [{
|
|
145
|
+
messageId: 'noAssertions',
|
|
146
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
147
|
+
}]
|
|
148
|
+
}, {
|
|
149
|
+
code: 'it("should also fail",() => expectSaga(mySaga).returns());',
|
|
150
|
+
options: [{
|
|
151
|
+
assertFunctionNames: ['expect']
|
|
152
|
+
}],
|
|
153
|
+
errors: [{
|
|
154
|
+
messageId: 'noAssertions',
|
|
155
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
156
|
+
}]
|
|
157
|
+
}]
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// {
|
|
161
|
+
// code: `test('wildcard chained function', () => tester.foo().expect(123));`,
|
|
162
|
+
// options: [{ assertFunctionNames: ['tester.*.expect'] }],
|
|
163
|
+
// },
|
|
164
|
+
|
|
165
|
+
ruleTester.run('wildcards', _expectExpect.default, {
|
|
166
|
+
valid: [{
|
|
167
|
+
code: "test('should pass *', () => expect404ToBeLoaded());",
|
|
168
|
+
options: [{
|
|
169
|
+
assertFunctionNames: ['expect*']
|
|
170
|
+
}]
|
|
171
|
+
}, {
|
|
172
|
+
code: "test('should pass *', () => expect.toHaveStatus404());",
|
|
173
|
+
options: [{
|
|
174
|
+
assertFunctionNames: ['expect.**']
|
|
175
|
+
}]
|
|
176
|
+
}, {
|
|
177
|
+
code: "test('should pass', () => tester.foo().expect(123));",
|
|
178
|
+
options: [{
|
|
179
|
+
assertFunctionNames: ['tester.*.expect']
|
|
180
|
+
}]
|
|
181
|
+
}, {
|
|
182
|
+
code: "test('should pass **', () => tester.foo().expect(123));",
|
|
183
|
+
options: [{
|
|
184
|
+
assertFunctionNames: ['**']
|
|
185
|
+
}]
|
|
186
|
+
}, {
|
|
187
|
+
code: "test('should pass *', () => tester.foo().expect(123));",
|
|
188
|
+
options: [{
|
|
189
|
+
assertFunctionNames: ['*']
|
|
190
|
+
}]
|
|
191
|
+
}, {
|
|
192
|
+
code: "test('should pass', () => tester.foo().expect(123));",
|
|
193
|
+
options: [{
|
|
194
|
+
assertFunctionNames: ['tester.**']
|
|
195
|
+
}]
|
|
196
|
+
}, {
|
|
197
|
+
code: "test('should pass', () => tester.foo().expect(123));",
|
|
198
|
+
options: [{
|
|
199
|
+
assertFunctionNames: ['tester.*']
|
|
200
|
+
}]
|
|
201
|
+
}, {
|
|
202
|
+
code: "test('should pass', () => tester.foo().bar().expectIt(456));",
|
|
203
|
+
options: [{
|
|
204
|
+
assertFunctionNames: ['tester.**.expect*']
|
|
205
|
+
}]
|
|
206
|
+
}, {
|
|
207
|
+
code: "test('should pass', () => request.get().foo().expect(456));",
|
|
208
|
+
options: [{
|
|
209
|
+
assertFunctionNames: ['request.**.expect']
|
|
210
|
+
}]
|
|
211
|
+
}, {
|
|
212
|
+
code: "test('should pass', () => request.get().foo().expect(456));",
|
|
213
|
+
options: [{
|
|
214
|
+
assertFunctionNames: ['request.**.e*e*t']
|
|
215
|
+
}]
|
|
216
|
+
}],
|
|
217
|
+
invalid: [{
|
|
218
|
+
code: "test('should fail', () => request.get().foo().expect(456));",
|
|
219
|
+
options: [{
|
|
220
|
+
assertFunctionNames: ['request.*.expect']
|
|
221
|
+
}],
|
|
222
|
+
errors: [{
|
|
223
|
+
messageId: 'noAssertions',
|
|
224
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
225
|
+
}]
|
|
226
|
+
}, {
|
|
227
|
+
code: "test('should fail', () => request.get().foo().bar().expect(456));",
|
|
228
|
+
options: [{
|
|
229
|
+
assertFunctionNames: ['request.foo**.expect']
|
|
230
|
+
}],
|
|
231
|
+
errors: [{
|
|
232
|
+
messageId: 'noAssertions',
|
|
233
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
234
|
+
}]
|
|
235
|
+
}, {
|
|
236
|
+
code: "test('should fail', () => tester.request(123));",
|
|
237
|
+
options: [{
|
|
238
|
+
assertFunctionNames: ['request.*']
|
|
239
|
+
}],
|
|
240
|
+
errors: [{
|
|
241
|
+
messageId: 'noAssertions',
|
|
242
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
243
|
+
}]
|
|
244
|
+
}, {
|
|
245
|
+
code: "test('should fail', () => request(123));",
|
|
246
|
+
options: [{
|
|
247
|
+
assertFunctionNames: ['request.*']
|
|
248
|
+
}],
|
|
249
|
+
errors: [{
|
|
250
|
+
messageId: 'noAssertions',
|
|
251
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
252
|
+
}]
|
|
253
|
+
}, {
|
|
254
|
+
code: "test('should fail', () => request(123));",
|
|
255
|
+
options: [{
|
|
256
|
+
assertFunctionNames: ['request.**']
|
|
257
|
+
}],
|
|
258
|
+
errors: [{
|
|
259
|
+
messageId: 'noAssertions',
|
|
260
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
261
|
+
}]
|
|
262
|
+
}]
|
|
263
|
+
});
|
|
264
|
+
ruleTester.run('expect-expect (aliases)', _expectExpect.default, {
|
|
265
|
+
valid: [{
|
|
266
|
+
code: (0, _dedent.default)`
|
|
267
|
+
import { test } from '@jest/globals';
|
|
268
|
+
|
|
269
|
+
test('should pass', () => {
|
|
270
|
+
expect(true).toBeDefined();
|
|
271
|
+
foo(true).toBe(true);
|
|
272
|
+
});
|
|
273
|
+
`,
|
|
274
|
+
options: [{
|
|
275
|
+
assertFunctionNames: ['expect', 'foo']
|
|
276
|
+
}],
|
|
277
|
+
parserOptions: {
|
|
278
|
+
sourceType: 'module'
|
|
279
|
+
}
|
|
280
|
+
}, {
|
|
281
|
+
code: (0, _dedent.default)`
|
|
282
|
+
import { test as checkThat } from '@jest/globals';
|
|
283
|
+
|
|
284
|
+
checkThat('this passes', () => {
|
|
285
|
+
expect(true).toBeDefined();
|
|
286
|
+
foo(true).toBe(true);
|
|
287
|
+
});
|
|
288
|
+
`,
|
|
289
|
+
options: [{
|
|
290
|
+
assertFunctionNames: ['expect', 'foo']
|
|
291
|
+
}],
|
|
292
|
+
parserOptions: {
|
|
293
|
+
sourceType: 'module'
|
|
294
|
+
}
|
|
295
|
+
}, {
|
|
296
|
+
code: (0, _dedent.default)`
|
|
297
|
+
const { test } = require('@jest/globals');
|
|
298
|
+
|
|
299
|
+
test('verifies chained expect method call', () => {
|
|
300
|
+
tester
|
|
301
|
+
.foo()
|
|
302
|
+
.bar()
|
|
303
|
+
.expect(456);
|
|
304
|
+
});
|
|
305
|
+
`,
|
|
306
|
+
options: [{
|
|
307
|
+
assertFunctionNames: ['tester.foo.bar.expect']
|
|
308
|
+
}],
|
|
309
|
+
parserOptions: {
|
|
310
|
+
sourceType: 'module'
|
|
311
|
+
}
|
|
312
|
+
}],
|
|
313
|
+
invalid: [{
|
|
314
|
+
code: (0, _dedent.default)`
|
|
315
|
+
import { test as checkThat } from '@jest/globals';
|
|
316
|
+
|
|
317
|
+
checkThat('this passes', () => {
|
|
318
|
+
// ...
|
|
319
|
+
});
|
|
320
|
+
`,
|
|
321
|
+
options: [{
|
|
322
|
+
assertFunctionNames: ['expect', 'foo']
|
|
323
|
+
}],
|
|
324
|
+
parserOptions: {
|
|
325
|
+
sourceType: 'module'
|
|
326
|
+
},
|
|
327
|
+
errors: [{
|
|
328
|
+
messageId: 'noAssertions',
|
|
329
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
330
|
+
}]
|
|
331
|
+
}, {
|
|
332
|
+
code: (0, _dedent.default)`
|
|
333
|
+
import { test as checkThat } from '@jest/globals';
|
|
334
|
+
|
|
335
|
+
checkThat.skip('this passes', () => {
|
|
336
|
+
// ...
|
|
337
|
+
});
|
|
338
|
+
`,
|
|
339
|
+
parserOptions: {
|
|
340
|
+
sourceType: 'module'
|
|
341
|
+
},
|
|
342
|
+
errors: [{
|
|
343
|
+
messageId: 'noAssertions',
|
|
344
|
+
type: _utils.AST_NODE_TYPES.CallExpression
|
|
345
|
+
}]
|
|
346
|
+
}]
|
|
347
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// used by no-throw-literal test case to validate custom error
|
|
2
|
+
export class Error {}
|
|
3
|
+
|
|
4
|
+
// used by unbound-method test case to test imports
|
|
5
|
+
export const console = { log() {} };
|
|
6
|
+
|
|
7
|
+
// used by prefer-reduce-type-parameter to test native vs userland check
|
|
8
|
+
export class Reducable {
|
|
9
|
+
reduce() {}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// used by no-implied-eval test function imports
|
|
13
|
+
export class Function {}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type T = number;
|