eslint-plugin-jest 27.2.2 → 27.3.0

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.
Files changed (77) hide show
  1. package/README.md +1 -0
  2. package/docs/rules/no-confusing-set-timeout.md +62 -0
  3. package/lib/rules/expect-expect.js +3 -1
  4. package/lib/rules/no-confusing-set-timeout.js +65 -0
  5. package/lib/rules/no-deprecated-functions.js +2 -2
  6. package/lib/rules/no-test-return-statement.js +9 -3
  7. package/lib/rules/no-untyped-mock-factory.js +3 -1
  8. package/lib/rules/prefer-spy-on.js +6 -2
  9. package/lib/rules/unbound-method.js +1 -1
  10. package/package.json +13 -16
  11. package/lib/processors/__tests__/snapshot-processor.test.js +0 -36
  12. package/lib/rules/__tests__/consistent-test-it.test.js +0 -921
  13. package/lib/rules/__tests__/expect-expect.test.js +0 -347
  14. package/lib/rules/__tests__/fixtures/class.ts +0 -13
  15. package/lib/rules/__tests__/fixtures/file.ts +0 -0
  16. package/lib/rules/__tests__/fixtures/foo.ts +0 -1
  17. package/lib/rules/__tests__/fixtures/indent/indent-invalid-fixture-1.js +0 -530
  18. package/lib/rules/__tests__/fixtures/indent/indent-valid-fixture-1.js +0 -530
  19. package/lib/rules/__tests__/fixtures/react.tsx +0 -0
  20. package/lib/rules/__tests__/fixtures/tsconfig-withmeta.json +0 -6
  21. package/lib/rules/__tests__/fixtures/tsconfig.json +0 -16
  22. package/lib/rules/__tests__/fixtures/unstrict/file.ts +0 -0
  23. package/lib/rules/__tests__/fixtures/unstrict/react.tsx +0 -0
  24. package/lib/rules/__tests__/fixtures/unstrict/tsconfig.json +0 -15
  25. package/lib/rules/__tests__/max-expects.test.js +0 -330
  26. package/lib/rules/__tests__/max-nested-describe.test.js +0 -247
  27. package/lib/rules/__tests__/no-alias-methods.test.js +0 -190
  28. package/lib/rules/__tests__/no-commented-out-tests.test.js +0 -213
  29. package/lib/rules/__tests__/no-conditional-expect.test.js +0 -696
  30. package/lib/rules/__tests__/no-conditional-in-test.test.js +0 -777
  31. package/lib/rules/__tests__/no-deprecated-functions.test.js +0 -119
  32. package/lib/rules/__tests__/no-disabled-tests.test.js +0 -241
  33. package/lib/rules/__tests__/no-done-callback.test.js +0 -424
  34. package/lib/rules/__tests__/no-duplicate-hooks.test.js +0 -469
  35. package/lib/rules/__tests__/no-export.test.js +0 -107
  36. package/lib/rules/__tests__/no-focused-tests.test.js +0 -373
  37. package/lib/rules/__tests__/no-hooks.test.js +0 -90
  38. package/lib/rules/__tests__/no-identical-title.test.js +0 -270
  39. package/lib/rules/__tests__/no-if.test.js +0 -787
  40. package/lib/rules/__tests__/no-interpolation-in-snapshots.test.js +0 -58
  41. package/lib/rules/__tests__/no-jasmine-globals.test.js +0 -206
  42. package/lib/rules/__tests__/no-large-snapshots.test.js +0 -237
  43. package/lib/rules/__tests__/no-mocks-import.test.js +0 -73
  44. package/lib/rules/__tests__/no-restricted-jest-methods.test.js +0 -103
  45. package/lib/rules/__tests__/no-restricted-matchers.test.js +0 -244
  46. package/lib/rules/__tests__/no-standalone-expect.test.js +0 -230
  47. package/lib/rules/__tests__/no-test-prefixes.test.js +0 -206
  48. package/lib/rules/__tests__/no-test-return-statement.test.js +0 -122
  49. package/lib/rules/__tests__/no-untyped-mock-factory.test.js +0 -149
  50. package/lib/rules/__tests__/prefer-called-with.test.js +0 -40
  51. package/lib/rules/__tests__/prefer-comparison-matcher.test.js +0 -200
  52. package/lib/rules/__tests__/prefer-each.test.js +0 -295
  53. package/lib/rules/__tests__/prefer-equality-matcher.test.js +0 -184
  54. package/lib/rules/__tests__/prefer-expect-assertions.test.js +0 -1437
  55. package/lib/rules/__tests__/prefer-expect-resolves.test.js +0 -96
  56. package/lib/rules/__tests__/prefer-hooks-in-order.test.js +0 -678
  57. package/lib/rules/__tests__/prefer-hooks-on-top.test.js +0 -218
  58. package/lib/rules/__tests__/prefer-lowercase-title.test.js +0 -619
  59. package/lib/rules/__tests__/prefer-mock-promise-shorthand.test.js +0 -360
  60. package/lib/rules/__tests__/prefer-snapshot-hint.test.js +0 -784
  61. package/lib/rules/__tests__/prefer-spy-on.test.js +0 -100
  62. package/lib/rules/__tests__/prefer-strict-equal.test.js +0 -46
  63. package/lib/rules/__tests__/prefer-to-be.test.js +0 -438
  64. package/lib/rules/__tests__/prefer-to-contain.test.js +0 -301
  65. package/lib/rules/__tests__/prefer-to-have-length.test.js +0 -99
  66. package/lib/rules/__tests__/prefer-todo.test.js +0 -78
  67. package/lib/rules/__tests__/require-hook.test.js +0 -403
  68. package/lib/rules/__tests__/require-to-throw-message.test.js +0 -108
  69. package/lib/rules/__tests__/require-top-level-describe.test.js +0 -236
  70. package/lib/rules/__tests__/test-utils.js +0 -11
  71. package/lib/rules/__tests__/unbound-method.test.js +0 -518
  72. package/lib/rules/__tests__/valid-describe-callback.test.js +0 -305
  73. package/lib/rules/__tests__/valid-expect-in-promise.test.js +0 -1583
  74. package/lib/rules/__tests__/valid-expect.test.js +0 -894
  75. package/lib/rules/__tests__/valid-title.test.js +0 -1147
  76. package/lib/rules/utils/__tests__/detectJestVersion.test.js +0 -221
  77. package/lib/rules/utils/__tests__/parseJestFnCall.test.js +0 -809
@@ -1,58 +0,0 @@
1
- "use strict";
2
-
3
- var _utils = require("@typescript-eslint/utils");
4
- var _noInterpolationInSnapshots = _interopRequireDefault(require("../no-interpolation-in-snapshots"));
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: 2017
11
- }
12
- });
13
- ruleTester.run('no-interpolation-in-snapshots', _noInterpolationInSnapshots.default, {
14
- valid: ['expect("something").toEqual("else");', 'expect(something).toMatchInlineSnapshot();', 'expect(something).toMatchInlineSnapshot(`No interpolation`);', 'expect(something).toMatchInlineSnapshot({}, `No interpolation`);', 'expect(something);', 'expect(something).not;', 'expect.toHaveAssertions();', 'myObjectWants.toMatchInlineSnapshot({}, `${interpolated}`);', 'myObjectWants.toMatchInlineSnapshot({}, `${interpolated1} ${interpolated2}`);', 'toMatchInlineSnapshot({}, `${interpolated}`);', 'toMatchInlineSnapshot({}, `${interpolated1} ${interpolated2}`);', 'expect(something).toThrowErrorMatchingInlineSnapshot();', 'expect(something).toThrowErrorMatchingInlineSnapshot(`No interpolation`);'],
15
- invalid: [{
16
- code: 'expect(something).toMatchInlineSnapshot(`${interpolated}`);',
17
- errors: [{
18
- endColumn: 58,
19
- column: 41,
20
- messageId: 'noInterpolation'
21
- }]
22
- }, {
23
- code: 'expect(something).not.toMatchInlineSnapshot(`${interpolated}`);',
24
- errors: [{
25
- endColumn: 62,
26
- column: 45,
27
- messageId: 'noInterpolation'
28
- }]
29
- }, {
30
- code: 'expect(something).toMatchInlineSnapshot({}, `${interpolated}`);',
31
- errors: [{
32
- endColumn: 62,
33
- column: 45,
34
- messageId: 'noInterpolation'
35
- }]
36
- }, {
37
- code: 'expect(something).not.toMatchInlineSnapshot({}, `${interpolated}`);',
38
- errors: [{
39
- endColumn: 66,
40
- column: 49,
41
- messageId: 'noInterpolation'
42
- }]
43
- }, {
44
- code: 'expect(something).toThrowErrorMatchingInlineSnapshot(`${interpolated}`);',
45
- errors: [{
46
- endColumn: 71,
47
- column: 54,
48
- messageId: 'noInterpolation'
49
- }]
50
- }, {
51
- code: 'expect(something).not.toThrowErrorMatchingInlineSnapshot(`${interpolated}`);',
52
- errors: [{
53
- endColumn: 75,
54
- column: 58,
55
- messageId: 'noInterpolation'
56
- }]
57
- }]
58
- });
@@ -1,206 +0,0 @@
1
- "use strict";
2
-
3
- var _utils = require("@typescript-eslint/utils");
4
- var _noJasmineGlobals = _interopRequireDefault(require("../no-jasmine-globals"));
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
- const ruleTester = new _utils.TSESLint.RuleTester();
7
- ruleTester.run('no-jasmine-globals', _noJasmineGlobals.default, {
8
- valid: ['jest.spyOn()', 'jest.fn()', 'expect.extend()', 'expect.any()', 'it("foo", function () {})', 'test("foo", function () {})', 'foo()', `require('foo')('bar')`, '(function(){})()', 'function callback(fail) { fail() }', 'var spyOn = require("actions"); spyOn("foo")', 'function callback(pending) { pending() }'],
9
- invalid: [{
10
- code: 'spyOn(some, "object")',
11
- output: null,
12
- errors: [{
13
- messageId: 'illegalGlobal',
14
- data: {
15
- global: 'spyOn',
16
- replacement: 'jest.spyOn'
17
- },
18
- column: 1,
19
- line: 1
20
- }]
21
- }, {
22
- code: 'spyOnProperty(some, "object")',
23
- output: null,
24
- errors: [{
25
- messageId: 'illegalGlobal',
26
- data: {
27
- global: 'spyOnProperty',
28
- replacement: 'jest.spyOn'
29
- },
30
- column: 1,
31
- line: 1
32
- }]
33
- }, {
34
- code: 'fail()',
35
- output: null,
36
- errors: [{
37
- messageId: 'illegalFail',
38
- column: 1,
39
- line: 1
40
- }]
41
- }, {
42
- code: 'pending()',
43
- output: null,
44
- errors: [{
45
- messageId: 'illegalPending',
46
- column: 1,
47
- line: 1
48
- }]
49
- }, {
50
- code: 'jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;',
51
- output: 'jest.setTimeout(5000);',
52
- errors: [{
53
- messageId: 'illegalJasmine',
54
- column: 1,
55
- line: 1
56
- }]
57
- }, {
58
- code: 'jasmine.DEFAULT_TIMEOUT_INTERVAL = function() {}',
59
- output: null,
60
- errors: [{
61
- messageId: 'illegalJasmine',
62
- column: 1,
63
- line: 1
64
- }]
65
- }, {
66
- code: 'jasmine.addMatchers(matchers)',
67
- output: null,
68
- errors: [{
69
- messageId: 'illegalMethod',
70
- data: {
71
- method: 'jasmine.addMatchers',
72
- replacement: 'expect.extend'
73
- },
74
- column: 1,
75
- line: 1
76
- }]
77
- }, {
78
- code: 'jasmine.createSpy()',
79
- output: null,
80
- errors: [{
81
- messageId: 'illegalMethod',
82
- data: {
83
- method: 'jasmine.createSpy',
84
- replacement: 'jest.fn'
85
- },
86
- column: 1,
87
- line: 1
88
- }]
89
- }, {
90
- code: 'jasmine.any()',
91
- output: 'expect.any()',
92
- errors: [{
93
- messageId: 'illegalMethod',
94
- data: {
95
- method: 'jasmine.any',
96
- replacement: 'expect.any'
97
- },
98
- column: 1,
99
- line: 1
100
- }]
101
- }, {
102
- code: 'jasmine.anything()',
103
- output: 'expect.anything()',
104
- errors: [{
105
- messageId: 'illegalMethod',
106
- data: {
107
- method: 'jasmine.anything',
108
- replacement: 'expect.anything'
109
- },
110
- column: 1,
111
- line: 1
112
- }]
113
- }, {
114
- code: 'jasmine.arrayContaining()',
115
- output: 'expect.arrayContaining()',
116
- errors: [{
117
- messageId: 'illegalMethod',
118
- data: {
119
- method: 'jasmine.arrayContaining',
120
- replacement: 'expect.arrayContaining'
121
- },
122
- column: 1,
123
- line: 1
124
- }]
125
- }, {
126
- code: 'jasmine.objectContaining()',
127
- output: 'expect.objectContaining()',
128
- errors: [{
129
- messageId: 'illegalMethod',
130
- data: {
131
- method: 'jasmine.objectContaining',
132
- replacement: 'expect.objectContaining'
133
- },
134
- column: 1,
135
- line: 1
136
- }]
137
- }, {
138
- code: 'jasmine.stringMatching()',
139
- output: 'expect.stringMatching()',
140
- errors: [{
141
- messageId: 'illegalMethod',
142
- data: {
143
- method: 'jasmine.stringMatching',
144
- replacement: 'expect.stringMatching'
145
- },
146
- column: 1,
147
- line: 1
148
- }]
149
- }, {
150
- code: 'jasmine.getEnv()',
151
- output: null,
152
- errors: [{
153
- messageId: 'illegalJasmine',
154
- column: 1,
155
- line: 1
156
- }]
157
- }, {
158
- code: 'jasmine.empty()',
159
- output: null,
160
- errors: [{
161
- messageId: 'illegalJasmine',
162
- column: 1,
163
- line: 1
164
- }]
165
- }, {
166
- code: 'jasmine.falsy()',
167
- output: null,
168
- errors: [{
169
- messageId: 'illegalJasmine',
170
- column: 1,
171
- line: 1
172
- }]
173
- }, {
174
- code: 'jasmine.truthy()',
175
- output: null,
176
- errors: [{
177
- messageId: 'illegalJasmine',
178
- column: 1,
179
- line: 1
180
- }]
181
- }, {
182
- code: 'jasmine.arrayWithExactContents()',
183
- output: null,
184
- errors: [{
185
- messageId: 'illegalJasmine',
186
- column: 1,
187
- line: 1
188
- }]
189
- }, {
190
- code: 'jasmine.clock()',
191
- output: null,
192
- errors: [{
193
- messageId: 'illegalJasmine',
194
- column: 1,
195
- line: 1
196
- }]
197
- }, {
198
- code: 'jasmine.MAX_PRETTY_PRINT_ARRAY_LENGTH = 42',
199
- output: null,
200
- errors: [{
201
- messageId: 'illegalJasmine',
202
- column: 1,
203
- line: 1
204
- }]
205
- }]
206
- });
@@ -1,237 +0,0 @@
1
- "use strict";
2
-
3
- var _utils = require("@typescript-eslint/utils");
4
- var _dedent = _interopRequireDefault(require("dedent"));
5
- var _noLargeSnapshots = _interopRequireDefault(require("../no-large-snapshots"));
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
- const generateSnapshotLines = lines => `\`\n${'line\n'.repeat(lines)}\``;
15
- const generateExportsSnapshotString = (lines, title = 'a big component 1') => `exports[\`${title}\`] = ${generateSnapshotLines(lines - 1)};`;
16
- const generateExpectInlineSnapsCode = (lines, matcher) => `expect(something).${matcher}(${generateSnapshotLines(lines)});`;
17
- ruleTester.run('no-large-snapshots', _noLargeSnapshots.default, {
18
- valid: ['expect(something)', 'expect(something).toBe(1)', 'expect(something).toMatchInlineSnapshot', 'expect(something).toMatchInlineSnapshot()', {
19
- filename: 'mock.js',
20
- code: generateExpectInlineSnapsCode(2, 'toMatchInlineSnapshot')
21
- }, {
22
- filename: 'mock.js',
23
- code: generateExpectInlineSnapsCode(2, 'toThrowErrorMatchingInlineSnapshot')
24
- }, {
25
- filename: 'mock.jsx',
26
- code: generateExpectInlineSnapsCode(20, 'toMatchInlineSnapshot'),
27
- options: [{
28
- maxSize: 19,
29
- inlineMaxSize: 21
30
- }]
31
- }, {
32
- filename: 'mock.jsx',
33
- code: generateExpectInlineSnapsCode(60, 'toMatchInlineSnapshot'),
34
- options: [{
35
- maxSize: 61
36
- }]
37
- }, {
38
- filename: 'mock.jsx',
39
- code: (0, _dedent.default)`
40
- expect(
41
- functionUnderTest(
42
- arg1,
43
- arg2,
44
- arg3
45
- )
46
- ).toMatchInlineSnapshot(${generateSnapshotLines(60)});
47
- `,
48
- options: [{
49
- maxSize: 61
50
- }]
51
- }, {
52
- // "should not report if node has fewer lines of code than limit"
53
- filename: '/mock-component.jsx.snap',
54
- code: generateExportsSnapshotString(20)
55
- }, {
56
- // "it should not report snapshots that are allowed to be large"
57
- filename: '/mock-component.jsx.snap',
58
- code: generateExportsSnapshotString(58),
59
- options: [{
60
- allowedSnapshots: {
61
- '/mock-component.jsx.snap': ['a big component 1']
62
- }
63
- }]
64
- }, {
65
- filename: '/mock-component.jsx.snap',
66
- code: generateExportsSnapshotString(20),
67
- options: [{
68
- maxSize: 21,
69
- inlineMaxSize: 19
70
- }]
71
- }],
72
- invalid: [{
73
- filename: 'mock.js',
74
- code: generateExpectInlineSnapsCode(50, 'toMatchInlineSnapshot'),
75
- errors: [{
76
- messageId: 'tooLongSnapshots',
77
- data: {
78
- lineLimit: 50,
79
- lineCount: 51
80
- }
81
- }]
82
- }, {
83
- filename: 'mock.js',
84
- code: generateExpectInlineSnapsCode(50, 'toThrowErrorMatchingInlineSnapshot'),
85
- errors: [{
86
- messageId: 'tooLongSnapshots',
87
- data: {
88
- lineLimit: 50,
89
- lineCount: 51
90
- }
91
- }]
92
- }, {
93
- filename: 'mock.js',
94
- code: generateExpectInlineSnapsCode(50, 'toThrowErrorMatchingInlineSnapshot'),
95
- options: [{
96
- maxSize: 51,
97
- inlineMaxSize: 50
98
- }],
99
- errors: [{
100
- messageId: 'tooLongSnapshots',
101
- data: {
102
- lineLimit: 50,
103
- lineCount: 51
104
- }
105
- }]
106
- }, {
107
- // "it should return an empty object for non snapshot files"
108
- filename: 'mock.jsx',
109
- code: generateExpectInlineSnapsCode(50, 'toMatchInlineSnapshot'),
110
- errors: [{
111
- messageId: 'tooLongSnapshots',
112
- data: {
113
- lineLimit: 50,
114
- lineCount: 51
115
- }
116
- }]
117
- }, {
118
- // "should report if node has more than 50 lines of code, and no sizeThreshold option is passed"
119
- filename: '/mock-component.jsx.snap',
120
- code: generateExportsSnapshotString(52),
121
- errors: [{
122
- messageId: 'tooLongSnapshots',
123
- data: {
124
- lineLimit: 50,
125
- lineCount: 52
126
- }
127
- }]
128
- }, {
129
- // "should report if node has more lines of code than number given in sizeThreshold option"
130
- filename: '/mock-component.jsx.snap',
131
- code: generateExportsSnapshotString(100),
132
- options: [{
133
- maxSize: 70
134
- }],
135
- errors: [{
136
- messageId: 'tooLongSnapshots',
137
- data: {
138
- lineLimit: 70,
139
- lineCount: 100
140
- }
141
- }]
142
- }, {
143
- filename: '/mock-component.jsx.snap',
144
- code: generateExportsSnapshotString(100),
145
- options: [{
146
- maxSize: 70,
147
- inlineMaxSize: 101
148
- }],
149
- errors: [{
150
- messageId: 'tooLongSnapshots',
151
- data: {
152
- lineLimit: 70,
153
- lineCount: 100
154
- }
155
- }]
156
- }, {
157
- // "should report if maxSize is zero"
158
- filename: '/mock-component.jsx.snap',
159
- code: generateExportsSnapshotString(1),
160
- options: [{
161
- maxSize: 0
162
- }],
163
- errors: [{
164
- messageId: 'noSnapshot',
165
- data: {
166
- lineLimit: 0,
167
- lineCount: 1
168
- }
169
- }]
170
- }, {
171
- // "it should report if file is not allowed"
172
- filename: '/mock-component.jsx.snap',
173
- code: generateExportsSnapshotString(58),
174
- options: [{
175
- allowedSnapshots: {
176
- '/another-mock-component.jsx.snap': [/a big component \d+/u]
177
- }
178
- }],
179
- errors: [{
180
- messageId: 'tooLongSnapshots',
181
- data: {
182
- lineLimit: 50,
183
- lineCount: 58
184
- }
185
- }]
186
- }, {
187
- // "should not report allowed large snapshots based on regexp"
188
- filename: '/mock-component.jsx.snap',
189
- code: [generateExportsSnapshotString(58, 'a big component w/ text'), generateExportsSnapshotString(58, 'a big component 2')].join('\n\n'),
190
- options: [{
191
- allowedSnapshots: {
192
- '/mock-component.jsx.snap': [/a big component \d+/u]
193
- }
194
- }],
195
- errors: [{
196
- messageId: 'tooLongSnapshots',
197
- data: {
198
- lineLimit: 50,
199
- lineCount: 58
200
- }
201
- }]
202
- }, {
203
- filename: '/mock-component.jsx.snap',
204
- code: [generateExportsSnapshotString(58, 'a big component w/ text'), generateExportsSnapshotString(58, 'a big component 2')].join('\n\n'),
205
- options: [{
206
- allowedSnapshots: {
207
- '/mock-component.jsx.snap': ['a big component 2']
208
- }
209
- }],
210
- errors: [{
211
- messageId: 'tooLongSnapshots',
212
- data: {
213
- lineLimit: 50,
214
- lineCount: 58
215
- }
216
- }]
217
- }]
218
- });
219
- describe('no-large-snapshots', () => {
220
- describe('when "allowedSnapshots" option contains relative paths', () => {
221
- it('should throw an exception', () => {
222
- expect(() => {
223
- const linter = new _utils.TSESLint.Linter();
224
- linter.defineRule('no-large-snapshots', _noLargeSnapshots.default);
225
- linter.verify('console.log()', {
226
- rules: {
227
- 'no-large-snapshots': ['error', {
228
- allowedSnapshots: {
229
- 'mock-component.jsx.snap': [/a big component \d+/u]
230
- }
231
- }]
232
- }
233
- }, 'mock-component.jsx.snap');
234
- }).toThrow('All paths for allowedSnapshots must be absolute. You can use JS config and `path.resolve`');
235
- });
236
- });
237
- });
@@ -1,73 +0,0 @@
1
- "use strict";
2
-
3
- var _utils = require("@typescript-eslint/utils");
4
- var _noMocksImport = _interopRequireDefault(require("../no-mocks-import"));
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: 2015
11
- }
12
- });
13
- ruleTester.run('no-mocks-import', _noMocksImport.default, {
14
- valid: [{
15
- code: 'import something from "something"',
16
- parserOptions: {
17
- sourceType: 'module'
18
- }
19
- }, 'require("somethingElse")', 'require("./__mocks__.js")', 'require("./__mocks__x")', 'require("./__mocks__x/x")', 'require("./x__mocks__")', 'require("./x__mocks__/x")', 'require()', 'var path = "./__mocks__.js"; require(path)', 'entirelyDifferent(fn)'],
20
- invalid: [{
21
- code: 'require("./__mocks__")',
22
- errors: [{
23
- endColumn: 22,
24
- column: 9,
25
- messageId: 'noManualImport'
26
- }]
27
- }, {
28
- code: 'require("./__mocks__/")',
29
- errors: [{
30
- endColumn: 23,
31
- column: 9,
32
- messageId: 'noManualImport'
33
- }]
34
- }, {
35
- code: 'require("./__mocks__/index")',
36
- errors: [{
37
- endColumn: 28,
38
- column: 9,
39
- messageId: 'noManualImport'
40
- }]
41
- }, {
42
- code: 'require("__mocks__")',
43
- errors: [{
44
- endColumn: 20,
45
- column: 9,
46
- messageId: 'noManualImport'
47
- }]
48
- }, {
49
- code: 'require("__mocks__/")',
50
- errors: [{
51
- endColumn: 21,
52
- column: 9,
53
- messageId: 'noManualImport'
54
- }]
55
- }, {
56
- code: 'require("__mocks__/index")',
57
- errors: [{
58
- endColumn: 26,
59
- column: 9,
60
- messageId: 'noManualImport'
61
- }]
62
- }, {
63
- code: 'import thing from "./__mocks__/index"',
64
- parserOptions: {
65
- sourceType: 'module'
66
- },
67
- errors: [{
68
- endColumn: 38,
69
- column: 1,
70
- messageId: 'noManualImport'
71
- }]
72
- }]
73
- });
@@ -1,103 +0,0 @@
1
- "use strict";
2
-
3
- var _utils = require("@typescript-eslint/utils");
4
- var _dedent = _interopRequireDefault(require("dedent"));
5
- var _noRestrictedJestMethods = _interopRequireDefault(require("../no-restricted-jest-methods"));
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: 2017
12
- }
13
- });
14
- ruleTester.run('no-restricted-jest-methods', _noRestrictedJestMethods.default, {
15
- valid: ['jest', 'jest()', 'jest.mock()', 'expect(a).rejects;', 'expect(a);', {
16
- code: (0, _dedent.default)`
17
- import { jest } from '@jest/globals';
18
-
19
- jest;
20
- `,
21
- parserOptions: {
22
- sourceType: 'module'
23
- }
24
- }],
25
- invalid: [{
26
- code: 'jest.fn()',
27
- options: [{
28
- fn: null
29
- }],
30
- errors: [{
31
- messageId: 'restrictedJestMethod',
32
- data: {
33
- message: null,
34
- restriction: 'fn'
35
- },
36
- column: 6,
37
- line: 1
38
- }]
39
- }, {
40
- code: 'jest["fn"]()',
41
- options: [{
42
- fn: null
43
- }],
44
- errors: [{
45
- messageId: 'restrictedJestMethod',
46
- data: {
47
- message: null,
48
- restriction: 'fn'
49
- },
50
- column: 6,
51
- line: 1
52
- }]
53
- }, {
54
- code: 'jest.mock()',
55
- options: [{
56
- mock: 'Do not use mocks'
57
- }],
58
- errors: [{
59
- messageId: 'restrictedJestMethodWithMessage',
60
- data: {
61
- message: 'Do not use mocks',
62
- restriction: 'mock'
63
- },
64
- column: 6,
65
- line: 1
66
- }]
67
- }, {
68
- code: 'jest["mock"]()',
69
- options: [{
70
- mock: 'Do not use mocks'
71
- }],
72
- errors: [{
73
- messageId: 'restrictedJestMethodWithMessage',
74
- data: {
75
- message: 'Do not use mocks',
76
- restriction: 'mock'
77
- },
78
- column: 6,
79
- line: 1
80
- }]
81
- }, {
82
- code: (0, _dedent.default)`
83
- import { jest } from '@jest/globals';
84
-
85
- jest.advanceTimersByTime();
86
- `,
87
- options: [{
88
- advanceTimersByTime: null
89
- }],
90
- parserOptions: {
91
- sourceType: 'module'
92
- },
93
- errors: [{
94
- messageId: 'restrictedJestMethod',
95
- data: {
96
- message: null,
97
- restriction: 'advanceTimersByTime'
98
- },
99
- column: 6,
100
- line: 3
101
- }]
102
- }]
103
- });