eslint-plugin-jest 27.2.2 → 27.2.3

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 (69) hide show
  1. package/lib/rules/no-deprecated-functions.js +2 -2
  2. package/package.json +6 -6
  3. package/lib/processors/__tests__/snapshot-processor.test.js +0 -36
  4. package/lib/rules/__tests__/consistent-test-it.test.js +0 -921
  5. package/lib/rules/__tests__/expect-expect.test.js +0 -347
  6. package/lib/rules/__tests__/fixtures/class.ts +0 -13
  7. package/lib/rules/__tests__/fixtures/file.ts +0 -0
  8. package/lib/rules/__tests__/fixtures/foo.ts +0 -1
  9. package/lib/rules/__tests__/fixtures/indent/indent-invalid-fixture-1.js +0 -530
  10. package/lib/rules/__tests__/fixtures/indent/indent-valid-fixture-1.js +0 -530
  11. package/lib/rules/__tests__/fixtures/react.tsx +0 -0
  12. package/lib/rules/__tests__/fixtures/tsconfig-withmeta.json +0 -6
  13. package/lib/rules/__tests__/fixtures/tsconfig.json +0 -16
  14. package/lib/rules/__tests__/fixtures/unstrict/file.ts +0 -0
  15. package/lib/rules/__tests__/fixtures/unstrict/react.tsx +0 -0
  16. package/lib/rules/__tests__/fixtures/unstrict/tsconfig.json +0 -15
  17. package/lib/rules/__tests__/max-expects.test.js +0 -330
  18. package/lib/rules/__tests__/max-nested-describe.test.js +0 -247
  19. package/lib/rules/__tests__/no-alias-methods.test.js +0 -190
  20. package/lib/rules/__tests__/no-commented-out-tests.test.js +0 -213
  21. package/lib/rules/__tests__/no-conditional-expect.test.js +0 -696
  22. package/lib/rules/__tests__/no-conditional-in-test.test.js +0 -777
  23. package/lib/rules/__tests__/no-deprecated-functions.test.js +0 -119
  24. package/lib/rules/__tests__/no-disabled-tests.test.js +0 -241
  25. package/lib/rules/__tests__/no-done-callback.test.js +0 -424
  26. package/lib/rules/__tests__/no-duplicate-hooks.test.js +0 -469
  27. package/lib/rules/__tests__/no-export.test.js +0 -107
  28. package/lib/rules/__tests__/no-focused-tests.test.js +0 -373
  29. package/lib/rules/__tests__/no-hooks.test.js +0 -90
  30. package/lib/rules/__tests__/no-identical-title.test.js +0 -270
  31. package/lib/rules/__tests__/no-if.test.js +0 -787
  32. package/lib/rules/__tests__/no-interpolation-in-snapshots.test.js +0 -58
  33. package/lib/rules/__tests__/no-jasmine-globals.test.js +0 -206
  34. package/lib/rules/__tests__/no-large-snapshots.test.js +0 -237
  35. package/lib/rules/__tests__/no-mocks-import.test.js +0 -73
  36. package/lib/rules/__tests__/no-restricted-jest-methods.test.js +0 -103
  37. package/lib/rules/__tests__/no-restricted-matchers.test.js +0 -244
  38. package/lib/rules/__tests__/no-standalone-expect.test.js +0 -230
  39. package/lib/rules/__tests__/no-test-prefixes.test.js +0 -206
  40. package/lib/rules/__tests__/no-test-return-statement.test.js +0 -122
  41. package/lib/rules/__tests__/no-untyped-mock-factory.test.js +0 -149
  42. package/lib/rules/__tests__/prefer-called-with.test.js +0 -40
  43. package/lib/rules/__tests__/prefer-comparison-matcher.test.js +0 -200
  44. package/lib/rules/__tests__/prefer-each.test.js +0 -295
  45. package/lib/rules/__tests__/prefer-equality-matcher.test.js +0 -184
  46. package/lib/rules/__tests__/prefer-expect-assertions.test.js +0 -1437
  47. package/lib/rules/__tests__/prefer-expect-resolves.test.js +0 -96
  48. package/lib/rules/__tests__/prefer-hooks-in-order.test.js +0 -678
  49. package/lib/rules/__tests__/prefer-hooks-on-top.test.js +0 -218
  50. package/lib/rules/__tests__/prefer-lowercase-title.test.js +0 -619
  51. package/lib/rules/__tests__/prefer-mock-promise-shorthand.test.js +0 -360
  52. package/lib/rules/__tests__/prefer-snapshot-hint.test.js +0 -784
  53. package/lib/rules/__tests__/prefer-spy-on.test.js +0 -100
  54. package/lib/rules/__tests__/prefer-strict-equal.test.js +0 -46
  55. package/lib/rules/__tests__/prefer-to-be.test.js +0 -438
  56. package/lib/rules/__tests__/prefer-to-contain.test.js +0 -301
  57. package/lib/rules/__tests__/prefer-to-have-length.test.js +0 -99
  58. package/lib/rules/__tests__/prefer-todo.test.js +0 -78
  59. package/lib/rules/__tests__/require-hook.test.js +0 -403
  60. package/lib/rules/__tests__/require-to-throw-message.test.js +0 -108
  61. package/lib/rules/__tests__/require-top-level-describe.test.js +0 -236
  62. package/lib/rules/__tests__/test-utils.js +0 -11
  63. package/lib/rules/__tests__/unbound-method.test.js +0 -518
  64. package/lib/rules/__tests__/valid-describe-callback.test.js +0 -305
  65. package/lib/rules/__tests__/valid-expect-in-promise.test.js +0 -1583
  66. package/lib/rules/__tests__/valid-expect.test.js +0 -894
  67. package/lib/rules/__tests__/valid-title.test.js +0 -1147
  68. package/lib/rules/utils/__tests__/detectJestVersion.test.js +0 -221
  69. package/lib/rules/utils/__tests__/parseJestFnCall.test.js +0 -809
@@ -1,119 +0,0 @@
1
- "use strict";
2
-
3
- var _utils = require("@typescript-eslint/utils");
4
- var _noDeprecatedFunctions = _interopRequireDefault(require("../no-deprecated-functions"));
5
- var _detectJestVersion = require("../utils/detectJestVersion");
6
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
- jest.mock('../utils/detectJestVersion');
8
- const detectJestVersionMock = _detectJestVersion.detectJestVersion;
9
- const ruleTester = new _utils.TSESLint.RuleTester();
10
- const generateValidCases = (jestVersion, functionCall) => {
11
- const [name, func] = functionCall.split('.');
12
- const settings = {
13
- jest: {
14
- version: jestVersion
15
- }
16
- };
17
- return [{
18
- settings,
19
- code: `${functionCall}()`
20
- }, {
21
- settings,
22
- code: `${functionCall}`
23
- }, {
24
- settings,
25
- code: `${name}['${func}']()`
26
- }, {
27
- settings,
28
- code: `${name}['${func}']`
29
- }];
30
- };
31
- const generateInvalidCases = (jestVersion, deprecation, replacement) => {
32
- const [deprecatedName, deprecatedFunc] = deprecation.split('.');
33
- const [replacementName, replacementFunc] = replacement.split('.');
34
- const settings = {
35
- jest: {
36
- version: jestVersion
37
- }
38
- };
39
- const errors = [{
40
- messageId: 'deprecatedFunction',
41
- data: {
42
- deprecation,
43
- replacement
44
- }
45
- }];
46
- return [{
47
- code: `${deprecation}()`,
48
- output: `${replacement}()`,
49
- settings,
50
- errors
51
- }, {
52
- code: `${deprecatedName}['${deprecatedFunc}']()`,
53
- output: `${replacementName}['${replacementFunc}']()`,
54
- settings,
55
- errors
56
- }];
57
- };
58
-
59
- // contains the cache-clearing beforeEach so we can test the cache too
60
- describe('the rule', () => {
61
- // a few sanity checks before doing our massive loop
62
- ruleTester.run('no-deprecated-functions', _noDeprecatedFunctions.default, {
63
- valid: [{
64
- code: 'jest',
65
- settings: {
66
- jest: {
67
- version: 14
68
- }
69
- }
70
- }, {
71
- code: 'require("fs")',
72
- settings: {
73
- jest: {
74
- version: 14
75
- }
76
- }
77
- }, ...generateValidCases(14, 'jest.resetModuleRegistry'), ...generateValidCases(17, 'require.requireActual'), ...generateValidCases(25, 'jest.genMockFromModule'), ...generateValidCases('25.1.1', 'jest.genMockFromModule'), ...generateValidCases('17.2', 'require.requireActual')],
78
- invalid: [...generateInvalidCases(21, 'jest.resetModuleRegistry', 'jest.resetModules'), ...generateInvalidCases(24, 'jest.addMatchers', 'expect.extend'), ...generateInvalidCases(26, 'jest.genMockFromModule', 'jest.createMockFromModule'), ...generateInvalidCases('26.0.0-next.11', 'jest.genMockFromModule', 'jest.createMockFromModule')]
79
- });
80
- describe.each([14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27])('when using jest version %i', jestVersion => {
81
- beforeEach(async () => {
82
- detectJestVersionMock.mockReturnValue(jestVersion);
83
- });
84
- const allowedFunctions = [];
85
- const deprecations = [[15, 'jest.resetModuleRegistry', 'jest.resetModules'], [17, 'jest.addMatchers', 'expect.extend'], [21, 'require.requireMock', 'jest.requireMock'], [21, 'require.requireActual', 'jest.requireActual'], [22, 'jest.runTimersToTime', 'jest.advanceTimersByTime'], [26, 'jest.genMockFromModule', 'jest.createMockFromModule']].filter(deprecation => {
86
- if (deprecation[0] > jestVersion) {
87
- allowedFunctions.push(deprecation[1]);
88
- return false;
89
- }
90
- return true;
91
- });
92
- ruleTester.run('explict jest version', _noDeprecatedFunctions.default, {
93
- valid: ['jest', 'require("fs")', ...allowedFunctions.map(func => generateValidCases(jestVersion, func)).reduce((acc, arr) => acc.concat(arr), [])],
94
- invalid: deprecations.map(([, deprecation, replacement]) => generateInvalidCases(jestVersion, deprecation, replacement)).reduce((acc, arr) => acc.concat(arr), [])
95
- });
96
- ruleTester.run('detected jest version', _noDeprecatedFunctions.default, {
97
- valid: ['jest', 'require("fs")', ...allowedFunctions.map(func => generateValidCases(undefined, func)).reduce((acc, arr) => acc.concat(arr), [])],
98
- invalid: deprecations.map(([, deprecation, replacement]) => generateInvalidCases(undefined, deprecation, replacement)).reduce((acc, arr) => acc.concat(arr), [])
99
- });
100
- });
101
- describe('when there is an error in detecting the jest version', () => {
102
- beforeEach(() => {
103
- detectJestVersionMock.mockImplementation(() => {
104
- throw new Error('oh noes!');
105
- });
106
- });
107
- it('bubbles the error up', () => {
108
- expect(() => {
109
- const linter = new _utils.TSESLint.Linter();
110
- linter.defineRule('no-deprecated-functions', _noDeprecatedFunctions.default);
111
- linter.verify('jest.resetModuleRegistry()', {
112
- rules: {
113
- 'no-deprecated-functions': 'error'
114
- }
115
- });
116
- }).toThrow('oh noes!');
117
- });
118
- });
119
- });
@@ -1,241 +0,0 @@
1
- "use strict";
2
-
3
- var _utils = require("@typescript-eslint/utils");
4
- var _dedent = _interopRequireDefault(require("dedent"));
5
- var _noDisabledTests = _interopRequireDefault(require("../no-disabled-tests"));
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
- sourceType: 'module'
13
- }
14
- });
15
- ruleTester.run('no-disabled-tests', _noDisabledTests.default, {
16
- valid: ['describe("foo", function () {})', 'it("foo", function () {})', 'describe.only("foo", function () {})', 'it.only("foo", function () {})', 'it.each("foo", () => {})', 'it.concurrent("foo", function () {})', 'test("foo", function () {})', 'test.only("foo", function () {})', 'test.concurrent("foo", function () {})', 'describe[`${"skip"}`]("foo", function () {})', 'it.todo("fill this later")', 'var appliedSkip = describe.skip; appliedSkip.apply(describe)', 'var calledSkip = it.skip; calledSkip.call(it)', '({ f: function () {} }).f()', '(a || b).f()', 'itHappensToStartWithIt()', 'testSomething()', 'xitSomethingElse()', 'xitiViewMap()', (0, _dedent.default)`
17
- import { pending } from "actions"
18
-
19
- test("foo", () => {
20
- expect(pending()).toEqual({})
21
- })
22
- `, (0, _dedent.default)`
23
- const { pending } = require("actions")
24
-
25
- test("foo", () => {
26
- expect(pending()).toEqual({})
27
- })
28
- `, (0, _dedent.default)`
29
- test("foo", () => {
30
- const pending = getPending()
31
- expect(pending()).toEqual({})
32
- })
33
- `, (0, _dedent.default)`
34
- test("foo", () => {
35
- expect(pending()).toEqual({})
36
- })
37
-
38
- function pending() {
39
- return {}
40
- }
41
- `, {
42
- code: (0, _dedent.default)`
43
- import { test } from './test-utils';
44
-
45
- test('something');
46
- `,
47
- parserOptions: {
48
- sourceType: 'module'
49
- }
50
- }],
51
- invalid: [{
52
- code: 'describe.skip("foo", function () {})',
53
- errors: [{
54
- messageId: 'disabledSuite',
55
- column: 1,
56
- line: 1
57
- }]
58
- }, {
59
- code: 'describe.skip.each([1, 2, 3])("%s", (a, b) => {});',
60
- errors: [{
61
- messageId: 'disabledSuite',
62
- column: 1,
63
- line: 1
64
- }]
65
- }, {
66
- code: 'xdescribe.each([1, 2, 3])("%s", (a, b) => {});',
67
- errors: [{
68
- messageId: 'disabledSuite',
69
- column: 1,
70
- line: 1
71
- }]
72
- }, {
73
- code: 'describe[`skip`]("foo", function () {})',
74
- errors: [{
75
- messageId: 'disabledSuite',
76
- column: 1,
77
- line: 1
78
- }]
79
- }, {
80
- code: 'describe["skip"]("foo", function () {})',
81
- errors: [{
82
- messageId: 'disabledSuite',
83
- column: 1,
84
- line: 1
85
- }]
86
- }, {
87
- code: 'it.skip("foo", function () {})',
88
- errors: [{
89
- messageId: 'disabledTest',
90
- column: 1,
91
- line: 1
92
- }]
93
- }, {
94
- code: 'it["skip"]("foo", function () {})',
95
- errors: [{
96
- messageId: 'disabledTest',
97
- column: 1,
98
- line: 1
99
- }]
100
- }, {
101
- code: 'test.skip("foo", function () {})',
102
- errors: [{
103
- messageId: 'disabledTest',
104
- column: 1,
105
- line: 1
106
- }]
107
- }, {
108
- code: 'it.skip.each``("foo", function () {})',
109
- errors: [{
110
- messageId: 'disabledTest',
111
- column: 1,
112
- line: 1
113
- }]
114
- }, {
115
- code: 'test.skip.each``("foo", function () {})',
116
- errors: [{
117
- messageId: 'disabledTest',
118
- column: 1,
119
- line: 1
120
- }]
121
- }, {
122
- code: 'it.skip.each([])("foo", function () {})',
123
- errors: [{
124
- messageId: 'disabledTest',
125
- column: 1,
126
- line: 1
127
- }]
128
- }, {
129
- code: 'test.skip.each([])("foo", function () {})',
130
- errors: [{
131
- messageId: 'disabledTest',
132
- column: 1,
133
- line: 1
134
- }]
135
- }, {
136
- code: 'test["skip"]("foo", function () {})',
137
- errors: [{
138
- messageId: 'disabledTest',
139
- column: 1,
140
- line: 1
141
- }]
142
- }, {
143
- code: 'xdescribe("foo", function () {})',
144
- errors: [{
145
- messageId: 'disabledSuite',
146
- column: 1,
147
- line: 1
148
- }]
149
- }, {
150
- code: 'xit("foo", function () {})',
151
- errors: [{
152
- messageId: 'disabledTest',
153
- column: 1,
154
- line: 1
155
- }]
156
- }, {
157
- code: 'xtest("foo", function () {})',
158
- errors: [{
159
- messageId: 'disabledTest',
160
- column: 1,
161
- line: 1
162
- }]
163
- }, {
164
- code: 'xit.each``("foo", function () {})',
165
- errors: [{
166
- messageId: 'disabledTest',
167
- column: 1,
168
- line: 1
169
- }]
170
- }, {
171
- code: 'xtest.each``("foo", function () {})',
172
- errors: [{
173
- messageId: 'disabledTest',
174
- column: 1,
175
- line: 1
176
- }]
177
- }, {
178
- code: 'xit.each([])("foo", function () {})',
179
- errors: [{
180
- messageId: 'disabledTest',
181
- column: 1,
182
- line: 1
183
- }]
184
- }, {
185
- code: 'xtest.each([])("foo", function () {})',
186
- errors: [{
187
- messageId: 'disabledTest',
188
- column: 1,
189
- line: 1
190
- }]
191
- }, {
192
- code: 'it("has title but no callback")',
193
- errors: [{
194
- messageId: 'missingFunction',
195
- column: 1,
196
- line: 1
197
- }]
198
- }, {
199
- code: 'test("has title but no callback")',
200
- errors: [{
201
- messageId: 'missingFunction',
202
- column: 1,
203
- line: 1
204
- }]
205
- }, {
206
- code: 'it("contains a call to pending", function () { pending() })',
207
- errors: [{
208
- messageId: 'pendingTest',
209
- column: 48,
210
- line: 1
211
- }]
212
- }, {
213
- code: 'pending();',
214
- errors: [{
215
- messageId: 'pending',
216
- column: 1,
217
- line: 1
218
- }]
219
- }, {
220
- code: 'describe("contains a call to pending", function () { pending() })',
221
- errors: [{
222
- messageId: 'pendingSuite',
223
- column: 54,
224
- line: 1
225
- }]
226
- }, {
227
- code: (0, _dedent.default)`
228
- import { test } from '@jest/globals';
229
-
230
- test('something');
231
- `,
232
- parserOptions: {
233
- sourceType: 'module'
234
- },
235
- errors: [{
236
- messageId: 'missingFunction',
237
- column: 1,
238
- line: 3
239
- }]
240
- }]
241
- });