eslint-plugin-jest 27.2.1 → 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-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 +2 -0
- 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/package.json +12 -8
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _utils = require("@typescript-eslint/utils");
|
|
4
|
+
var _dedent = _interopRequireDefault(require("dedent"));
|
|
5
|
+
var _preferToContain = _interopRequireDefault(require("../prefer-to-contain"));
|
|
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('prefer-to-contain', _preferToContain.default, {
|
|
15
|
+
valid: ['expect.hasAssertions', 'expect.hasAssertions()', 'expect.assertions(1)', 'expect().toBe(false);', 'expect(a).toContain(b);', "expect(a.name).toBe('b');", 'expect(a).toBe(true);', `expect(a).toEqual(b)`, `expect(a.test(c)).toEqual(b)`, `expect(a.includes(b)).toEqual()`, `expect(a.includes(b)).toEqual("test")`, `expect(a.includes(b)).toBe("test")`, `expect(a.includes()).toEqual()`, `expect(a.includes()).toEqual(true)`, `expect(a.includes(b,c)).toBe(true)`, `expect([{a:1}]).toContain({a:1})`, `expect([1].includes(1)).toEqual`, `expect([1].includes).toEqual`, `expect([1].includes).not`, `expect(a.test(b)).resolves.toEqual(true)`, `expect(a.test(b)).resolves.not.toEqual(true)`, `expect(a).not.toContain(b)`, 'expect(a.includes(...[])).toBe(true)', 'expect(a.includes(b)).toBe(...true)', 'expect(a);'],
|
|
16
|
+
invalid: [{
|
|
17
|
+
code: 'expect(a.includes(b)).toEqual(true);',
|
|
18
|
+
output: 'expect(a).toContain(b);',
|
|
19
|
+
errors: [{
|
|
20
|
+
messageId: 'useToContain',
|
|
21
|
+
column: 23,
|
|
22
|
+
line: 1
|
|
23
|
+
}]
|
|
24
|
+
}, {
|
|
25
|
+
code: 'expect(a.includes(b,),).toEqual(true,);',
|
|
26
|
+
output: 'expect(a,).toContain(b,);',
|
|
27
|
+
parserOptions: {
|
|
28
|
+
ecmaVersion: 2017
|
|
29
|
+
},
|
|
30
|
+
errors: [{
|
|
31
|
+
messageId: 'useToContain',
|
|
32
|
+
column: 25,
|
|
33
|
+
line: 1
|
|
34
|
+
}]
|
|
35
|
+
}, {
|
|
36
|
+
code: "expect(a['includes'](b)).toEqual(true);",
|
|
37
|
+
output: 'expect(a).toContain(b);',
|
|
38
|
+
errors: [{
|
|
39
|
+
messageId: 'useToContain',
|
|
40
|
+
column: 26,
|
|
41
|
+
line: 1
|
|
42
|
+
}]
|
|
43
|
+
}, {
|
|
44
|
+
code: "expect(a['includes'](b))['toEqual'](true);",
|
|
45
|
+
output: 'expect(a).toContain(b);',
|
|
46
|
+
errors: [{
|
|
47
|
+
messageId: 'useToContain',
|
|
48
|
+
column: 26,
|
|
49
|
+
line: 1
|
|
50
|
+
}]
|
|
51
|
+
}, {
|
|
52
|
+
code: "expect(a['includes'](b)).toEqual(false);",
|
|
53
|
+
output: 'expect(a).not.toContain(b);',
|
|
54
|
+
errors: [{
|
|
55
|
+
messageId: 'useToContain',
|
|
56
|
+
column: 26,
|
|
57
|
+
line: 1
|
|
58
|
+
}]
|
|
59
|
+
}, {
|
|
60
|
+
code: "expect(a['includes'](b)).not.toEqual(false);",
|
|
61
|
+
output: 'expect(a).toContain(b);',
|
|
62
|
+
errors: [{
|
|
63
|
+
messageId: 'useToContain',
|
|
64
|
+
column: 30,
|
|
65
|
+
line: 1
|
|
66
|
+
}]
|
|
67
|
+
}, {
|
|
68
|
+
code: "expect(a['includes'](b))['not'].toEqual(false);",
|
|
69
|
+
output: 'expect(a).toContain(b);',
|
|
70
|
+
errors: [{
|
|
71
|
+
messageId: 'useToContain',
|
|
72
|
+
column: 33,
|
|
73
|
+
line: 1
|
|
74
|
+
}]
|
|
75
|
+
}, {
|
|
76
|
+
code: "expect(a['includes'](b))['not']['toEqual'](false);",
|
|
77
|
+
output: 'expect(a).toContain(b);',
|
|
78
|
+
errors: [{
|
|
79
|
+
messageId: 'useToContain',
|
|
80
|
+
column: 33,
|
|
81
|
+
line: 1
|
|
82
|
+
}]
|
|
83
|
+
}, {
|
|
84
|
+
code: 'expect(a.includes(b)).toEqual(false);',
|
|
85
|
+
output: 'expect(a).not.toContain(b);',
|
|
86
|
+
errors: [{
|
|
87
|
+
messageId: 'useToContain',
|
|
88
|
+
column: 23,
|
|
89
|
+
line: 1
|
|
90
|
+
}]
|
|
91
|
+
}, {
|
|
92
|
+
code: 'expect(a.includes(b)).not.toEqual(false);',
|
|
93
|
+
output: 'expect(a).toContain(b);',
|
|
94
|
+
errors: [{
|
|
95
|
+
messageId: 'useToContain',
|
|
96
|
+
column: 27,
|
|
97
|
+
line: 1
|
|
98
|
+
}]
|
|
99
|
+
}, {
|
|
100
|
+
code: 'expect(a.includes(b)).not.toEqual(true);',
|
|
101
|
+
output: 'expect(a).not.toContain(b);',
|
|
102
|
+
errors: [{
|
|
103
|
+
messageId: 'useToContain',
|
|
104
|
+
column: 27,
|
|
105
|
+
line: 1
|
|
106
|
+
}]
|
|
107
|
+
}, {
|
|
108
|
+
code: 'expect(a.includes(b)).toBe(true);',
|
|
109
|
+
output: 'expect(a).toContain(b);',
|
|
110
|
+
errors: [{
|
|
111
|
+
messageId: 'useToContain',
|
|
112
|
+
column: 23,
|
|
113
|
+
line: 1
|
|
114
|
+
}]
|
|
115
|
+
}, {
|
|
116
|
+
code: 'expect(a.includes(b)).toBe(false);',
|
|
117
|
+
output: 'expect(a).not.toContain(b);',
|
|
118
|
+
errors: [{
|
|
119
|
+
messageId: 'useToContain',
|
|
120
|
+
column: 23,
|
|
121
|
+
line: 1
|
|
122
|
+
}]
|
|
123
|
+
}, {
|
|
124
|
+
code: 'expect(a.includes(b)).not.toBe(false);',
|
|
125
|
+
output: 'expect(a).toContain(b);',
|
|
126
|
+
errors: [{
|
|
127
|
+
messageId: 'useToContain',
|
|
128
|
+
column: 27,
|
|
129
|
+
line: 1
|
|
130
|
+
}]
|
|
131
|
+
}, {
|
|
132
|
+
code: 'expect(a.includes(b)).not.toBe(true);',
|
|
133
|
+
output: 'expect(a).not.toContain(b);',
|
|
134
|
+
errors: [{
|
|
135
|
+
messageId: 'useToContain',
|
|
136
|
+
column: 27,
|
|
137
|
+
line: 1
|
|
138
|
+
}]
|
|
139
|
+
}, {
|
|
140
|
+
code: 'expect(a.includes(b)).toStrictEqual(true);',
|
|
141
|
+
output: 'expect(a).toContain(b);',
|
|
142
|
+
errors: [{
|
|
143
|
+
messageId: 'useToContain',
|
|
144
|
+
column: 23,
|
|
145
|
+
line: 1
|
|
146
|
+
}]
|
|
147
|
+
}, {
|
|
148
|
+
code: 'expect(a.includes(b)).toStrictEqual(false);',
|
|
149
|
+
output: 'expect(a).not.toContain(b);',
|
|
150
|
+
errors: [{
|
|
151
|
+
messageId: 'useToContain',
|
|
152
|
+
column: 23,
|
|
153
|
+
line: 1
|
|
154
|
+
}]
|
|
155
|
+
}, {
|
|
156
|
+
code: 'expect(a.includes(b)).not.toStrictEqual(false);',
|
|
157
|
+
output: 'expect(a).toContain(b);',
|
|
158
|
+
errors: [{
|
|
159
|
+
messageId: 'useToContain',
|
|
160
|
+
column: 27,
|
|
161
|
+
line: 1
|
|
162
|
+
}]
|
|
163
|
+
}, {
|
|
164
|
+
code: 'expect(a.includes(b)).not.toStrictEqual(true);',
|
|
165
|
+
output: 'expect(a).not.toContain(b);',
|
|
166
|
+
errors: [{
|
|
167
|
+
messageId: 'useToContain',
|
|
168
|
+
column: 27,
|
|
169
|
+
line: 1
|
|
170
|
+
}]
|
|
171
|
+
}, {
|
|
172
|
+
code: 'expect(a.test(t).includes(b.test(p))).toEqual(true);',
|
|
173
|
+
output: 'expect(a.test(t)).toContain(b.test(p));',
|
|
174
|
+
errors: [{
|
|
175
|
+
messageId: 'useToContain',
|
|
176
|
+
column: 39,
|
|
177
|
+
line: 1
|
|
178
|
+
}]
|
|
179
|
+
}, {
|
|
180
|
+
code: 'expect(a.test(t).includes(b.test(p))).toEqual(false);',
|
|
181
|
+
output: 'expect(a.test(t)).not.toContain(b.test(p));',
|
|
182
|
+
errors: [{
|
|
183
|
+
messageId: 'useToContain',
|
|
184
|
+
column: 39,
|
|
185
|
+
line: 1
|
|
186
|
+
}]
|
|
187
|
+
}, {
|
|
188
|
+
code: 'expect(a.test(t).includes(b.test(p))).not.toEqual(true);',
|
|
189
|
+
output: 'expect(a.test(t)).not.toContain(b.test(p));',
|
|
190
|
+
errors: [{
|
|
191
|
+
messageId: 'useToContain',
|
|
192
|
+
column: 43,
|
|
193
|
+
line: 1
|
|
194
|
+
}]
|
|
195
|
+
}, {
|
|
196
|
+
code: 'expect(a.test(t).includes(b.test(p))).not.toEqual(false);',
|
|
197
|
+
output: 'expect(a.test(t)).toContain(b.test(p));',
|
|
198
|
+
errors: [{
|
|
199
|
+
messageId: 'useToContain',
|
|
200
|
+
column: 43,
|
|
201
|
+
line: 1
|
|
202
|
+
}]
|
|
203
|
+
}, {
|
|
204
|
+
code: 'expect([{a:1}].includes({a:1})).toBe(true);',
|
|
205
|
+
output: 'expect([{a:1}]).toContain({a:1});',
|
|
206
|
+
errors: [{
|
|
207
|
+
messageId: 'useToContain',
|
|
208
|
+
column: 33,
|
|
209
|
+
line: 1
|
|
210
|
+
}]
|
|
211
|
+
}, {
|
|
212
|
+
code: 'expect([{a:1}].includes({a:1})).toBe(false);',
|
|
213
|
+
output: 'expect([{a:1}]).not.toContain({a:1});',
|
|
214
|
+
errors: [{
|
|
215
|
+
messageId: 'useToContain',
|
|
216
|
+
column: 33,
|
|
217
|
+
line: 1
|
|
218
|
+
}]
|
|
219
|
+
}, {
|
|
220
|
+
code: 'expect([{a:1}].includes({a:1})).not.toBe(true);',
|
|
221
|
+
output: 'expect([{a:1}]).not.toContain({a:1});',
|
|
222
|
+
errors: [{
|
|
223
|
+
messageId: 'useToContain',
|
|
224
|
+
column: 37,
|
|
225
|
+
line: 1
|
|
226
|
+
}]
|
|
227
|
+
}, {
|
|
228
|
+
code: 'expect([{a:1}].includes({a:1})).not.toBe(false);',
|
|
229
|
+
output: 'expect([{a:1}]).toContain({a:1});',
|
|
230
|
+
errors: [{
|
|
231
|
+
messageId: 'useToContain',
|
|
232
|
+
column: 37,
|
|
233
|
+
line: 1
|
|
234
|
+
}]
|
|
235
|
+
}, {
|
|
236
|
+
code: 'expect([{a:1}].includes({a:1})).toStrictEqual(true);',
|
|
237
|
+
output: 'expect([{a:1}]).toContain({a:1});',
|
|
238
|
+
errors: [{
|
|
239
|
+
messageId: 'useToContain',
|
|
240
|
+
column: 33,
|
|
241
|
+
line: 1
|
|
242
|
+
}]
|
|
243
|
+
}, {
|
|
244
|
+
code: 'expect([{a:1}].includes({a:1})).toStrictEqual(false);',
|
|
245
|
+
output: 'expect([{a:1}]).not.toContain({a:1});',
|
|
246
|
+
errors: [{
|
|
247
|
+
messageId: 'useToContain',
|
|
248
|
+
column: 33,
|
|
249
|
+
line: 1
|
|
250
|
+
}]
|
|
251
|
+
}, {
|
|
252
|
+
code: 'expect([{a:1}].includes({a:1})).not.toStrictEqual(true);',
|
|
253
|
+
output: 'expect([{a:1}]).not.toContain({a:1});',
|
|
254
|
+
errors: [{
|
|
255
|
+
messageId: 'useToContain',
|
|
256
|
+
column: 37,
|
|
257
|
+
line: 1
|
|
258
|
+
}]
|
|
259
|
+
}, {
|
|
260
|
+
code: 'expect([{a:1}].includes({a:1})).not.toStrictEqual(false);',
|
|
261
|
+
output: 'expect([{a:1}]).toContain({a:1});',
|
|
262
|
+
errors: [{
|
|
263
|
+
messageId: 'useToContain',
|
|
264
|
+
column: 37,
|
|
265
|
+
line: 1
|
|
266
|
+
}]
|
|
267
|
+
}, {
|
|
268
|
+
code: (0, _dedent.default)`
|
|
269
|
+
import { expect as pleaseExpect } from '@jest/globals';
|
|
270
|
+
|
|
271
|
+
pleaseExpect([{a:1}].includes({a:1})).not.toStrictEqual(false);
|
|
272
|
+
`,
|
|
273
|
+
output: (0, _dedent.default)`
|
|
274
|
+
import { expect as pleaseExpect } from '@jest/globals';
|
|
275
|
+
|
|
276
|
+
pleaseExpect([{a:1}]).toContain({a:1});
|
|
277
|
+
`,
|
|
278
|
+
parserOptions: {
|
|
279
|
+
sourceType: 'module'
|
|
280
|
+
},
|
|
281
|
+
errors: [{
|
|
282
|
+
messageId: 'useToContain',
|
|
283
|
+
column: 43,
|
|
284
|
+
line: 3
|
|
285
|
+
}]
|
|
286
|
+
}]
|
|
287
|
+
});
|
|
288
|
+
new _utils.TSESLint.RuleTester({
|
|
289
|
+
parser: require.resolve('@typescript-eslint/parser')
|
|
290
|
+
}).run('prefer-to-be-null: typescript edition', _preferToContain.default, {
|
|
291
|
+
valid: ["(expect('Model must be bound to an array if the multiple property is true') as any).toHaveBeenTipped()", 'expect(a.includes(b)).toEqual(0 as boolean);'],
|
|
292
|
+
invalid: [{
|
|
293
|
+
code: 'expect(a.includes(b)).toEqual(false as boolean);',
|
|
294
|
+
output: 'expect(a).not.toContain(b);',
|
|
295
|
+
errors: [{
|
|
296
|
+
messageId: 'useToContain',
|
|
297
|
+
column: 23,
|
|
298
|
+
line: 1
|
|
299
|
+
}]
|
|
300
|
+
}]
|
|
301
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _utils = require("@typescript-eslint/utils");
|
|
4
|
+
var _preferToHaveLength = _interopRequireDefault(require("../prefer-to-have-length"));
|
|
5
|
+
var _testUtils = require("./test-utils");
|
|
6
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
|
+
const ruleTester = new _utils.TSESLint.RuleTester({
|
|
8
|
+
parser: _testUtils.espreeParser,
|
|
9
|
+
parserOptions: {
|
|
10
|
+
ecmaVersion: 2020
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
ruleTester.run('prefer-to-have-length', _preferToHaveLength.default, {
|
|
14
|
+
valid: ['expect.hasAssertions', 'expect.hasAssertions()', 'expect(files).toHaveLength(1);', "expect(files.name).toBe('file');", "expect(files[`name`]).toBe('file');", 'expect(users[0]?.permissions?.length).toBe(1);', 'expect(result).toBe(true);', `expect(user.getUserName(5)).resolves.toEqual('Paul')`, `expect(user.getUserName(5)).rejects.toEqual('Paul')`, 'expect(a);'],
|
|
15
|
+
invalid: [{
|
|
16
|
+
code: 'expect(files["length"]).toBe(1);',
|
|
17
|
+
output: 'expect(files).toHaveLength(1);',
|
|
18
|
+
errors: [{
|
|
19
|
+
messageId: 'useToHaveLength',
|
|
20
|
+
column: 25,
|
|
21
|
+
line: 1
|
|
22
|
+
}]
|
|
23
|
+
}, {
|
|
24
|
+
code: 'expect(files["length"]).toBe(1,);',
|
|
25
|
+
output: 'expect(files).toHaveLength(1,);',
|
|
26
|
+
parserOptions: {
|
|
27
|
+
ecmaVersion: 2017
|
|
28
|
+
},
|
|
29
|
+
errors: [{
|
|
30
|
+
messageId: 'useToHaveLength',
|
|
31
|
+
column: 25,
|
|
32
|
+
line: 1
|
|
33
|
+
}]
|
|
34
|
+
}, {
|
|
35
|
+
code: 'expect(files["length"])["not"].toBe(1);',
|
|
36
|
+
output: 'expect(files)["not"].toHaveLength(1);',
|
|
37
|
+
errors: [{
|
|
38
|
+
messageId: 'useToHaveLength',
|
|
39
|
+
column: 32,
|
|
40
|
+
line: 1
|
|
41
|
+
}]
|
|
42
|
+
}, {
|
|
43
|
+
code: 'expect(files["length"])["toBe"](1);',
|
|
44
|
+
output: 'expect(files).toHaveLength(1);',
|
|
45
|
+
errors: [{
|
|
46
|
+
messageId: 'useToHaveLength',
|
|
47
|
+
column: 25,
|
|
48
|
+
line: 1
|
|
49
|
+
}]
|
|
50
|
+
}, {
|
|
51
|
+
code: 'expect(files["length"]).not["toBe"](1);',
|
|
52
|
+
output: 'expect(files).not.toHaveLength(1);',
|
|
53
|
+
errors: [{
|
|
54
|
+
messageId: 'useToHaveLength',
|
|
55
|
+
column: 29,
|
|
56
|
+
line: 1
|
|
57
|
+
}]
|
|
58
|
+
}, {
|
|
59
|
+
code: 'expect(files["length"])["not"]["toBe"](1);',
|
|
60
|
+
output: 'expect(files)["not"].toHaveLength(1);',
|
|
61
|
+
errors: [{
|
|
62
|
+
messageId: 'useToHaveLength',
|
|
63
|
+
column: 32,
|
|
64
|
+
line: 1
|
|
65
|
+
}]
|
|
66
|
+
}, {
|
|
67
|
+
code: 'expect(files.length).toBe(1);',
|
|
68
|
+
output: 'expect(files).toHaveLength(1);',
|
|
69
|
+
errors: [{
|
|
70
|
+
messageId: 'useToHaveLength',
|
|
71
|
+
column: 22,
|
|
72
|
+
line: 1
|
|
73
|
+
}]
|
|
74
|
+
}, {
|
|
75
|
+
code: 'expect(files.length).toEqual(1);',
|
|
76
|
+
output: 'expect(files).toHaveLength(1);',
|
|
77
|
+
errors: [{
|
|
78
|
+
messageId: 'useToHaveLength',
|
|
79
|
+
column: 22,
|
|
80
|
+
line: 1
|
|
81
|
+
}]
|
|
82
|
+
}, {
|
|
83
|
+
code: 'expect(files.length).toStrictEqual(1);',
|
|
84
|
+
output: 'expect(files).toHaveLength(1);',
|
|
85
|
+
errors: [{
|
|
86
|
+
messageId: 'useToHaveLength',
|
|
87
|
+
column: 22,
|
|
88
|
+
line: 1
|
|
89
|
+
}]
|
|
90
|
+
}, {
|
|
91
|
+
code: 'expect(files.length).not.toStrictEqual(1);',
|
|
92
|
+
output: 'expect(files).not.toHaveLength(1);',
|
|
93
|
+
errors: [{
|
|
94
|
+
messageId: 'useToHaveLength',
|
|
95
|
+
column: 26,
|
|
96
|
+
line: 1
|
|
97
|
+
}]
|
|
98
|
+
}]
|
|
99
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _utils = require("@typescript-eslint/utils");
|
|
4
|
+
var _dedent = _interopRequireDefault(require("dedent"));
|
|
5
|
+
var _preferTodo = _interopRequireDefault(require("../prefer-todo"));
|
|
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('prefer-todo', _preferTodo.default, {
|
|
15
|
+
valid: ['test()', 'test.concurrent()', 'test.todo("i need to write this test");', 'test(obj)', 'test.concurrent(obj)', 'fit("foo")', 'fit.concurrent("foo")', 'xit("foo")', 'test("foo", 1)', 'test("stub", () => expect(1).toBe(1));', 'test.concurrent("stub", () => expect(1).toBe(1));', (0, _dedent.default)`
|
|
16
|
+
supportsDone && params.length < test.length
|
|
17
|
+
? done => test(...params, done)
|
|
18
|
+
: () => test(...params);
|
|
19
|
+
`],
|
|
20
|
+
invalid: [{
|
|
21
|
+
code: `test("i need to write this test");`,
|
|
22
|
+
output: 'test.todo("i need to write this test");',
|
|
23
|
+
errors: [{
|
|
24
|
+
messageId: 'unimplementedTest'
|
|
25
|
+
}]
|
|
26
|
+
}, {
|
|
27
|
+
code: `test("i need to write this test",);`,
|
|
28
|
+
output: 'test.todo("i need to write this test",);',
|
|
29
|
+
parserOptions: {
|
|
30
|
+
ecmaVersion: 2017
|
|
31
|
+
},
|
|
32
|
+
errors: [{
|
|
33
|
+
messageId: 'unimplementedTest'
|
|
34
|
+
}]
|
|
35
|
+
}, {
|
|
36
|
+
code: 'test(`i need to write this test`);',
|
|
37
|
+
output: 'test.todo(`i need to write this test`);',
|
|
38
|
+
errors: [{
|
|
39
|
+
messageId: 'unimplementedTest'
|
|
40
|
+
}]
|
|
41
|
+
}, {
|
|
42
|
+
code: 'it("foo", function () {})',
|
|
43
|
+
output: 'it.todo("foo")',
|
|
44
|
+
errors: [{
|
|
45
|
+
messageId: 'emptyTest'
|
|
46
|
+
}]
|
|
47
|
+
}, {
|
|
48
|
+
code: 'it("foo", () => {})',
|
|
49
|
+
output: 'it.todo("foo")',
|
|
50
|
+
errors: [{
|
|
51
|
+
messageId: 'emptyTest'
|
|
52
|
+
}]
|
|
53
|
+
}, {
|
|
54
|
+
code: `test.skip("i need to write this test", () => {});`,
|
|
55
|
+
output: 'test.todo("i need to write this test");',
|
|
56
|
+
errors: [{
|
|
57
|
+
messageId: 'emptyTest'
|
|
58
|
+
}]
|
|
59
|
+
}, {
|
|
60
|
+
code: `test.skip("i need to write this test", function() {});`,
|
|
61
|
+
output: 'test.todo("i need to write this test");',
|
|
62
|
+
errors: [{
|
|
63
|
+
messageId: 'emptyTest'
|
|
64
|
+
}]
|
|
65
|
+
}, {
|
|
66
|
+
code: `test["skip"]("i need to write this test", function() {});`,
|
|
67
|
+
output: 'test[\'todo\']("i need to write this test");',
|
|
68
|
+
errors: [{
|
|
69
|
+
messageId: 'emptyTest'
|
|
70
|
+
}]
|
|
71
|
+
}, {
|
|
72
|
+
code: `test[\`skip\`]("i need to write this test", function() {});`,
|
|
73
|
+
output: 'test[\'todo\']("i need to write this test");',
|
|
74
|
+
errors: [{
|
|
75
|
+
messageId: 'emptyTest'
|
|
76
|
+
}]
|
|
77
|
+
}]
|
|
78
|
+
});
|