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.
- package/README.md +1 -0
- package/docs/rules/no-confusing-set-timeout.md +62 -0
- package/lib/rules/expect-expect.js +3 -1
- package/lib/rules/no-confusing-set-timeout.js +65 -0
- package/lib/rules/no-deprecated-functions.js +2 -2
- package/lib/rules/no-test-return-statement.js +9 -3
- package/lib/rules/no-untyped-mock-factory.js +3 -1
- package/lib/rules/prefer-spy-on.js +6 -2
- package/lib/rules/unbound-method.js +1 -1
- package/package.json +13 -16
- package/lib/processors/__tests__/snapshot-processor.test.js +0 -36
- package/lib/rules/__tests__/consistent-test-it.test.js +0 -921
- package/lib/rules/__tests__/expect-expect.test.js +0 -347
- package/lib/rules/__tests__/fixtures/class.ts +0 -13
- package/lib/rules/__tests__/fixtures/file.ts +0 -0
- package/lib/rules/__tests__/fixtures/foo.ts +0 -1
- package/lib/rules/__tests__/fixtures/indent/indent-invalid-fixture-1.js +0 -530
- package/lib/rules/__tests__/fixtures/indent/indent-valid-fixture-1.js +0 -530
- package/lib/rules/__tests__/fixtures/react.tsx +0 -0
- package/lib/rules/__tests__/fixtures/tsconfig-withmeta.json +0 -6
- package/lib/rules/__tests__/fixtures/tsconfig.json +0 -16
- 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 +0 -15
- package/lib/rules/__tests__/max-expects.test.js +0 -330
- package/lib/rules/__tests__/max-nested-describe.test.js +0 -247
- package/lib/rules/__tests__/no-alias-methods.test.js +0 -190
- package/lib/rules/__tests__/no-commented-out-tests.test.js +0 -213
- package/lib/rules/__tests__/no-conditional-expect.test.js +0 -696
- package/lib/rules/__tests__/no-conditional-in-test.test.js +0 -777
- package/lib/rules/__tests__/no-deprecated-functions.test.js +0 -119
- package/lib/rules/__tests__/no-disabled-tests.test.js +0 -241
- package/lib/rules/__tests__/no-done-callback.test.js +0 -424
- package/lib/rules/__tests__/no-duplicate-hooks.test.js +0 -469
- package/lib/rules/__tests__/no-export.test.js +0 -107
- package/lib/rules/__tests__/no-focused-tests.test.js +0 -373
- package/lib/rules/__tests__/no-hooks.test.js +0 -90
- package/lib/rules/__tests__/no-identical-title.test.js +0 -270
- package/lib/rules/__tests__/no-if.test.js +0 -787
- package/lib/rules/__tests__/no-interpolation-in-snapshots.test.js +0 -58
- package/lib/rules/__tests__/no-jasmine-globals.test.js +0 -206
- package/lib/rules/__tests__/no-large-snapshots.test.js +0 -237
- package/lib/rules/__tests__/no-mocks-import.test.js +0 -73
- package/lib/rules/__tests__/no-restricted-jest-methods.test.js +0 -103
- package/lib/rules/__tests__/no-restricted-matchers.test.js +0 -244
- package/lib/rules/__tests__/no-standalone-expect.test.js +0 -230
- package/lib/rules/__tests__/no-test-prefixes.test.js +0 -206
- package/lib/rules/__tests__/no-test-return-statement.test.js +0 -122
- package/lib/rules/__tests__/no-untyped-mock-factory.test.js +0 -149
- package/lib/rules/__tests__/prefer-called-with.test.js +0 -40
- package/lib/rules/__tests__/prefer-comparison-matcher.test.js +0 -200
- package/lib/rules/__tests__/prefer-each.test.js +0 -295
- package/lib/rules/__tests__/prefer-equality-matcher.test.js +0 -184
- package/lib/rules/__tests__/prefer-expect-assertions.test.js +0 -1437
- package/lib/rules/__tests__/prefer-expect-resolves.test.js +0 -96
- package/lib/rules/__tests__/prefer-hooks-in-order.test.js +0 -678
- package/lib/rules/__tests__/prefer-hooks-on-top.test.js +0 -218
- package/lib/rules/__tests__/prefer-lowercase-title.test.js +0 -619
- package/lib/rules/__tests__/prefer-mock-promise-shorthand.test.js +0 -360
- package/lib/rules/__tests__/prefer-snapshot-hint.test.js +0 -784
- package/lib/rules/__tests__/prefer-spy-on.test.js +0 -100
- package/lib/rules/__tests__/prefer-strict-equal.test.js +0 -46
- package/lib/rules/__tests__/prefer-to-be.test.js +0 -438
- package/lib/rules/__tests__/prefer-to-contain.test.js +0 -301
- package/lib/rules/__tests__/prefer-to-have-length.test.js +0 -99
- package/lib/rules/__tests__/prefer-todo.test.js +0 -78
- package/lib/rules/__tests__/require-hook.test.js +0 -403
- package/lib/rules/__tests__/require-to-throw-message.test.js +0 -108
- package/lib/rules/__tests__/require-top-level-describe.test.js +0 -236
- package/lib/rules/__tests__/test-utils.js +0 -11
- package/lib/rules/__tests__/unbound-method.test.js +0 -518
- package/lib/rules/__tests__/valid-describe-callback.test.js +0 -305
- package/lib/rules/__tests__/valid-expect-in-promise.test.js +0 -1583
- package/lib/rules/__tests__/valid-expect.test.js +0 -894
- package/lib/rules/__tests__/valid-title.test.js +0 -1147
- package/lib/rules/utils/__tests__/detectJestVersion.test.js +0 -221
- package/lib/rules/utils/__tests__/parseJestFnCall.test.js +0 -809
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _utils = require("@typescript-eslint/utils");
|
|
4
|
-
var _preferSpyOn = _interopRequireDefault(require("../prefer-spy-on"));
|
|
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('prefer-spy-on', _preferSpyOn.default, {
|
|
14
|
-
valid: ['Date.now = () => 10', 'window.fetch = jest.fn', 'Date.now = fn()', 'obj.mock = jest.something()', 'const mock = jest.fn()', 'mock = jest.fn()', 'const mockObj = { mock: jest.fn() }', 'mockObj = { mock: jest.fn() }', 'window[`${name}`] = jest[`fn${expression}`]()'],
|
|
15
|
-
invalid: [{
|
|
16
|
-
code: 'obj.a = jest.fn(); const test = 10;',
|
|
17
|
-
output: "jest.spyOn(obj, 'a').mockImplementation(); const test = 10;",
|
|
18
|
-
errors: [{
|
|
19
|
-
messageId: 'useJestSpyOn',
|
|
20
|
-
type: _utils.AST_NODE_TYPES.AssignmentExpression
|
|
21
|
-
}]
|
|
22
|
-
}, {
|
|
23
|
-
code: "Date['now'] = jest['fn']()",
|
|
24
|
-
output: "jest.spyOn(Date, 'now').mockImplementation()",
|
|
25
|
-
errors: [{
|
|
26
|
-
messageId: 'useJestSpyOn',
|
|
27
|
-
type: _utils.AST_NODE_TYPES.AssignmentExpression
|
|
28
|
-
}]
|
|
29
|
-
}, {
|
|
30
|
-
code: 'window[`${name}`] = jest[`fn`]()',
|
|
31
|
-
output: 'jest.spyOn(window, `${name}`).mockImplementation()',
|
|
32
|
-
errors: [{
|
|
33
|
-
messageId: 'useJestSpyOn',
|
|
34
|
-
type: _utils.AST_NODE_TYPES.AssignmentExpression
|
|
35
|
-
}]
|
|
36
|
-
}, {
|
|
37
|
-
code: "obj['prop' + 1] = jest['fn']()",
|
|
38
|
-
output: "jest.spyOn(obj, 'prop' + 1).mockImplementation()",
|
|
39
|
-
errors: [{
|
|
40
|
-
messageId: 'useJestSpyOn',
|
|
41
|
-
type: _utils.AST_NODE_TYPES.AssignmentExpression
|
|
42
|
-
}]
|
|
43
|
-
}, {
|
|
44
|
-
code: 'obj.one.two = jest.fn(); const test = 10;',
|
|
45
|
-
output: "jest.spyOn(obj.one, 'two').mockImplementation(); const test = 10;",
|
|
46
|
-
errors: [{
|
|
47
|
-
messageId: 'useJestSpyOn',
|
|
48
|
-
type: _utils.AST_NODE_TYPES.AssignmentExpression
|
|
49
|
-
}]
|
|
50
|
-
}, {
|
|
51
|
-
code: 'obj.a = jest.fn(() => 10,)',
|
|
52
|
-
output: "jest.spyOn(obj, 'a').mockImplementation(() => 10)",
|
|
53
|
-
parserOptions: {
|
|
54
|
-
ecmaVersion: 2017
|
|
55
|
-
},
|
|
56
|
-
errors: [{
|
|
57
|
-
messageId: 'useJestSpyOn',
|
|
58
|
-
type: _utils.AST_NODE_TYPES.AssignmentExpression
|
|
59
|
-
}]
|
|
60
|
-
}, {
|
|
61
|
-
code: "obj.a.b = jest.fn(() => ({})).mockReturnValue('default').mockReturnValueOnce('first call'); test();",
|
|
62
|
-
output: "jest.spyOn(obj.a, 'b').mockImplementation(() => ({})).mockReturnValue('default').mockReturnValueOnce('first call'); test();",
|
|
63
|
-
errors: [{
|
|
64
|
-
messageId: 'useJestSpyOn',
|
|
65
|
-
type: _utils.AST_NODE_TYPES.AssignmentExpression
|
|
66
|
-
}]
|
|
67
|
-
}, {
|
|
68
|
-
code: 'window.fetch = jest.fn(() => ({})).one.two().three().four',
|
|
69
|
-
output: "jest.spyOn(window, 'fetch').mockImplementation(() => ({})).one.two().three().four",
|
|
70
|
-
errors: [{
|
|
71
|
-
messageId: 'useJestSpyOn',
|
|
72
|
-
type: _utils.AST_NODE_TYPES.AssignmentExpression
|
|
73
|
-
}]
|
|
74
|
-
}, {
|
|
75
|
-
// https://github.com/jest-community/eslint-plugin-jest/issues/1304
|
|
76
|
-
code: 'foo[bar] = jest.fn().mockReturnValue(undefined)',
|
|
77
|
-
output: 'jest.spyOn(foo, bar).mockImplementation().mockReturnValue(undefined)',
|
|
78
|
-
errors: [{
|
|
79
|
-
messageId: 'useJestSpyOn',
|
|
80
|
-
type: _utils.AST_NODE_TYPES.AssignmentExpression
|
|
81
|
-
}]
|
|
82
|
-
}, {
|
|
83
|
-
// https://github.com/jest-community/eslint-plugin-jest/issues/1307
|
|
84
|
-
code: `
|
|
85
|
-
foo.bar = jest.fn().mockImplementation(baz => baz)
|
|
86
|
-
foo.bar = jest.fn(a => b).mockImplementation(baz => baz)
|
|
87
|
-
`,
|
|
88
|
-
output: `
|
|
89
|
-
jest.spyOn(foo, 'bar').mockImplementation(baz => baz)
|
|
90
|
-
jest.spyOn(foo, 'bar').mockImplementation(baz => baz)
|
|
91
|
-
`,
|
|
92
|
-
errors: [{
|
|
93
|
-
messageId: 'useJestSpyOn',
|
|
94
|
-
type: _utils.AST_NODE_TYPES.AssignmentExpression
|
|
95
|
-
}, {
|
|
96
|
-
messageId: 'useJestSpyOn',
|
|
97
|
-
type: _utils.AST_NODE_TYPES.AssignmentExpression
|
|
98
|
-
}]
|
|
99
|
-
}]
|
|
100
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _utils = require("@typescript-eslint/utils");
|
|
4
|
-
var _preferStrictEqual = _interopRequireDefault(require("../prefer-strict-equal"));
|
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
-
const ruleTester = new _utils.TSESLint.RuleTester();
|
|
7
|
-
ruleTester.run('prefer-strict-equal', _preferStrictEqual.default, {
|
|
8
|
-
valid: ['expect(something).toStrictEqual(somethingElse);', "a().toEqual('b')", 'expect(a);'],
|
|
9
|
-
invalid: [{
|
|
10
|
-
code: 'expect(something).toEqual(somethingElse);',
|
|
11
|
-
errors: [{
|
|
12
|
-
messageId: 'useToStrictEqual',
|
|
13
|
-
column: 19,
|
|
14
|
-
line: 1,
|
|
15
|
-
suggestions: [{
|
|
16
|
-
messageId: 'suggestReplaceWithStrictEqual',
|
|
17
|
-
output: 'expect(something).toStrictEqual(somethingElse);'
|
|
18
|
-
}]
|
|
19
|
-
}]
|
|
20
|
-
}, {
|
|
21
|
-
code: 'expect(something).toEqual(somethingElse,);',
|
|
22
|
-
parserOptions: {
|
|
23
|
-
ecmaVersion: 2017
|
|
24
|
-
},
|
|
25
|
-
errors: [{
|
|
26
|
-
messageId: 'useToStrictEqual',
|
|
27
|
-
column: 19,
|
|
28
|
-
line: 1,
|
|
29
|
-
suggestions: [{
|
|
30
|
-
messageId: 'suggestReplaceWithStrictEqual',
|
|
31
|
-
output: 'expect(something).toStrictEqual(somethingElse,);'
|
|
32
|
-
}]
|
|
33
|
-
}]
|
|
34
|
-
}, {
|
|
35
|
-
code: 'expect(something)["toEqual"](somethingElse);',
|
|
36
|
-
errors: [{
|
|
37
|
-
messageId: 'useToStrictEqual',
|
|
38
|
-
column: 19,
|
|
39
|
-
line: 1,
|
|
40
|
-
suggestions: [{
|
|
41
|
-
messageId: 'suggestReplaceWithStrictEqual',
|
|
42
|
-
output: "expect(something)['toStrictEqual'](somethingElse);"
|
|
43
|
-
}]
|
|
44
|
-
}]
|
|
45
|
-
}]
|
|
46
|
-
});
|
|
@@ -1,438 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _utils = require("@typescript-eslint/utils");
|
|
4
|
-
var _preferToBe = _interopRequireDefault(require("../prefer-to-be"));
|
|
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('prefer-to-be', _preferToBe.default, {
|
|
14
|
-
valid: ['expect(null).toBeNull();', 'expect(null).not.toBeNull();', 'expect(null).toBe(1);', 'expect(null).toBe(-1);', 'expect(null).toBe(...1);', 'expect(obj).toStrictEqual([ x, 1 ]);', 'expect(obj).toStrictEqual({ x: 1 });', 'expect(obj).not.toStrictEqual({ x: 1 });', 'expect(value).toMatchSnapshot();', "expect(catchError()).toStrictEqual({ message: 'oh noes!' })", 'expect("something");', 'expect(token).toStrictEqual(/[abc]+/g);', "expect(token).toStrictEqual(new RegExp('[abc]+', 'g'));", 'expect(value).toEqual(dedent`my string`);'],
|
|
15
|
-
invalid: [{
|
|
16
|
-
code: 'expect(value).toEqual("my string");',
|
|
17
|
-
output: 'expect(value).toBe("my string");',
|
|
18
|
-
errors: [{
|
|
19
|
-
messageId: 'useToBe',
|
|
20
|
-
column: 15,
|
|
21
|
-
line: 1
|
|
22
|
-
}]
|
|
23
|
-
}, {
|
|
24
|
-
code: 'expect(value).toStrictEqual("my string");',
|
|
25
|
-
output: 'expect(value).toBe("my string");',
|
|
26
|
-
errors: [{
|
|
27
|
-
messageId: 'useToBe',
|
|
28
|
-
column: 15,
|
|
29
|
-
line: 1
|
|
30
|
-
}]
|
|
31
|
-
}, {
|
|
32
|
-
code: 'expect(value).toStrictEqual(1);',
|
|
33
|
-
output: 'expect(value).toBe(1);',
|
|
34
|
-
errors: [{
|
|
35
|
-
messageId: 'useToBe',
|
|
36
|
-
column: 15,
|
|
37
|
-
line: 1
|
|
38
|
-
}]
|
|
39
|
-
}, {
|
|
40
|
-
code: 'expect(value).toStrictEqual(1,);',
|
|
41
|
-
output: 'expect(value).toBe(1,);',
|
|
42
|
-
parserOptions: {
|
|
43
|
-
ecmaVersion: 2017
|
|
44
|
-
},
|
|
45
|
-
errors: [{
|
|
46
|
-
messageId: 'useToBe',
|
|
47
|
-
column: 15,
|
|
48
|
-
line: 1
|
|
49
|
-
}]
|
|
50
|
-
}, {
|
|
51
|
-
code: 'expect(value).toStrictEqual(-1);',
|
|
52
|
-
output: 'expect(value).toBe(-1);',
|
|
53
|
-
errors: [{
|
|
54
|
-
messageId: 'useToBe',
|
|
55
|
-
column: 15,
|
|
56
|
-
line: 1
|
|
57
|
-
}]
|
|
58
|
-
}, {
|
|
59
|
-
code: 'expect(value).toEqual(`my string`);',
|
|
60
|
-
output: 'expect(value).toBe(`my string`);',
|
|
61
|
-
errors: [{
|
|
62
|
-
messageId: 'useToBe',
|
|
63
|
-
column: 15,
|
|
64
|
-
line: 1
|
|
65
|
-
}]
|
|
66
|
-
}, {
|
|
67
|
-
code: 'expect(value)["toEqual"](`my string`);',
|
|
68
|
-
output: "expect(value)['toBe'](`my string`);",
|
|
69
|
-
errors: [{
|
|
70
|
-
messageId: 'useToBe',
|
|
71
|
-
column: 15,
|
|
72
|
-
line: 1
|
|
73
|
-
}]
|
|
74
|
-
}, {
|
|
75
|
-
code: 'expect(value).toStrictEqual(`my ${string}`);',
|
|
76
|
-
output: 'expect(value).toBe(`my ${string}`);',
|
|
77
|
-
errors: [{
|
|
78
|
-
messageId: 'useToBe',
|
|
79
|
-
column: 15,
|
|
80
|
-
line: 1
|
|
81
|
-
}]
|
|
82
|
-
}, {
|
|
83
|
-
code: 'expect(loadMessage()).resolves.toStrictEqual("hello world");',
|
|
84
|
-
output: 'expect(loadMessage()).resolves.toBe("hello world");',
|
|
85
|
-
errors: [{
|
|
86
|
-
messageId: 'useToBe',
|
|
87
|
-
column: 32,
|
|
88
|
-
line: 1
|
|
89
|
-
}]
|
|
90
|
-
}, {
|
|
91
|
-
code: 'expect(loadMessage()).resolves["toStrictEqual"]("hello world");',
|
|
92
|
-
output: 'expect(loadMessage()).resolves[\'toBe\']("hello world");',
|
|
93
|
-
errors: [{
|
|
94
|
-
messageId: 'useToBe',
|
|
95
|
-
column: 32,
|
|
96
|
-
line: 1
|
|
97
|
-
}]
|
|
98
|
-
}, {
|
|
99
|
-
code: 'expect(loadMessage())["resolves"].toStrictEqual("hello world");',
|
|
100
|
-
output: 'expect(loadMessage())["resolves"].toBe("hello world");',
|
|
101
|
-
errors: [{
|
|
102
|
-
messageId: 'useToBe',
|
|
103
|
-
column: 35,
|
|
104
|
-
line: 1
|
|
105
|
-
}]
|
|
106
|
-
}, {
|
|
107
|
-
code: 'expect(loadMessage()).resolves.toStrictEqual(false);',
|
|
108
|
-
output: 'expect(loadMessage()).resolves.toBe(false);',
|
|
109
|
-
errors: [{
|
|
110
|
-
messageId: 'useToBe',
|
|
111
|
-
column: 32,
|
|
112
|
-
line: 1
|
|
113
|
-
}]
|
|
114
|
-
}]
|
|
115
|
-
});
|
|
116
|
-
ruleTester.run('prefer-to-be: null', _preferToBe.default, {
|
|
117
|
-
valid: ['expect(null).toBeNull();', 'expect(null).not.toBeNull();', 'expect(null).toBe(1);', 'expect(obj).toStrictEqual([ x, 1 ]);', 'expect(obj).toStrictEqual({ x: 1 });', 'expect(obj).not.toStrictEqual({ x: 1 });', 'expect(value).toMatchSnapshot();', "expect(catchError()).toStrictEqual({ message: 'oh noes!' })", 'expect("something");',
|
|
118
|
-
//
|
|
119
|
-
'expect(null).not.toEqual();', 'expect(null).toBe();', 'expect(null).toMatchSnapshot();', 'expect("a string").toMatchSnapshot(null);', 'expect("a string").not.toMatchSnapshot();', 'expect(null).toBe'],
|
|
120
|
-
invalid: [{
|
|
121
|
-
code: 'expect(null).toBe(null);',
|
|
122
|
-
output: 'expect(null).toBeNull();',
|
|
123
|
-
errors: [{
|
|
124
|
-
messageId: 'useToBeNull',
|
|
125
|
-
column: 14,
|
|
126
|
-
line: 1
|
|
127
|
-
}]
|
|
128
|
-
}, {
|
|
129
|
-
code: 'expect(null).toEqual(null);',
|
|
130
|
-
output: 'expect(null).toBeNull();',
|
|
131
|
-
errors: [{
|
|
132
|
-
messageId: 'useToBeNull',
|
|
133
|
-
column: 14,
|
|
134
|
-
line: 1
|
|
135
|
-
}]
|
|
136
|
-
}, {
|
|
137
|
-
code: 'expect(null).toEqual(null,);',
|
|
138
|
-
output: 'expect(null).toBeNull();',
|
|
139
|
-
parserOptions: {
|
|
140
|
-
ecmaVersion: 2017
|
|
141
|
-
},
|
|
142
|
-
errors: [{
|
|
143
|
-
messageId: 'useToBeNull',
|
|
144
|
-
column: 14,
|
|
145
|
-
line: 1
|
|
146
|
-
}]
|
|
147
|
-
}, {
|
|
148
|
-
code: 'expect(null).toStrictEqual(null);',
|
|
149
|
-
output: 'expect(null).toBeNull();',
|
|
150
|
-
errors: [{
|
|
151
|
-
messageId: 'useToBeNull',
|
|
152
|
-
column: 14,
|
|
153
|
-
line: 1
|
|
154
|
-
}]
|
|
155
|
-
}, {
|
|
156
|
-
code: 'expect("a string").not.toBe(null);',
|
|
157
|
-
output: 'expect("a string").not.toBeNull();',
|
|
158
|
-
errors: [{
|
|
159
|
-
messageId: 'useToBeNull',
|
|
160
|
-
column: 24,
|
|
161
|
-
line: 1
|
|
162
|
-
}]
|
|
163
|
-
}, {
|
|
164
|
-
code: 'expect("a string").not["toBe"](null);',
|
|
165
|
-
output: 'expect("a string").not[\'toBeNull\']();',
|
|
166
|
-
errors: [{
|
|
167
|
-
messageId: 'useToBeNull',
|
|
168
|
-
column: 24,
|
|
169
|
-
line: 1
|
|
170
|
-
}]
|
|
171
|
-
}, {
|
|
172
|
-
code: 'expect("a string")["not"]["toBe"](null);',
|
|
173
|
-
output: 'expect("a string")["not"][\'toBeNull\']();',
|
|
174
|
-
errors: [{
|
|
175
|
-
messageId: 'useToBeNull',
|
|
176
|
-
column: 27,
|
|
177
|
-
line: 1
|
|
178
|
-
}]
|
|
179
|
-
}, {
|
|
180
|
-
code: 'expect("a string").not.toEqual(null);',
|
|
181
|
-
output: 'expect("a string").not.toBeNull();',
|
|
182
|
-
errors: [{
|
|
183
|
-
messageId: 'useToBeNull',
|
|
184
|
-
column: 24,
|
|
185
|
-
line: 1
|
|
186
|
-
}]
|
|
187
|
-
}, {
|
|
188
|
-
code: 'expect("a string").not.toStrictEqual(null);',
|
|
189
|
-
output: 'expect("a string").not.toBeNull();',
|
|
190
|
-
errors: [{
|
|
191
|
-
messageId: 'useToBeNull',
|
|
192
|
-
column: 24,
|
|
193
|
-
line: 1
|
|
194
|
-
}]
|
|
195
|
-
}]
|
|
196
|
-
});
|
|
197
|
-
ruleTester.run('prefer-to-be: undefined', _preferToBe.default, {
|
|
198
|
-
valid: ['expect(undefined).toBeUndefined();', 'expect(true).toBeDefined();', 'expect({}).toEqual({});', 'expect(something).toBe()', 'expect(something).toBe(somethingElse)', 'expect(something).toEqual(somethingElse)', 'expect(something).not.toBe(somethingElse)', 'expect(something).not.toEqual(somethingElse)', 'expect(undefined).toBe', 'expect("something");'],
|
|
199
|
-
invalid: [{
|
|
200
|
-
code: 'expect(undefined).toBe(undefined);',
|
|
201
|
-
output: 'expect(undefined).toBeUndefined();',
|
|
202
|
-
errors: [{
|
|
203
|
-
messageId: 'useToBeUndefined',
|
|
204
|
-
column: 19,
|
|
205
|
-
line: 1
|
|
206
|
-
}]
|
|
207
|
-
}, {
|
|
208
|
-
code: 'expect(undefined).toEqual(undefined);',
|
|
209
|
-
output: 'expect(undefined).toBeUndefined();',
|
|
210
|
-
errors: [{
|
|
211
|
-
messageId: 'useToBeUndefined',
|
|
212
|
-
column: 19,
|
|
213
|
-
line: 1
|
|
214
|
-
}]
|
|
215
|
-
}, {
|
|
216
|
-
code: 'expect(undefined).toStrictEqual(undefined);',
|
|
217
|
-
output: 'expect(undefined).toBeUndefined();',
|
|
218
|
-
errors: [{
|
|
219
|
-
messageId: 'useToBeUndefined',
|
|
220
|
-
column: 19,
|
|
221
|
-
line: 1
|
|
222
|
-
}]
|
|
223
|
-
}, {
|
|
224
|
-
code: 'expect("a string").not.toBe(undefined);',
|
|
225
|
-
output: 'expect("a string").toBeDefined();',
|
|
226
|
-
errors: [{
|
|
227
|
-
messageId: 'useToBeDefined',
|
|
228
|
-
column: 24,
|
|
229
|
-
line: 1
|
|
230
|
-
}]
|
|
231
|
-
}, {
|
|
232
|
-
code: 'expect("a string").rejects.not.toBe(undefined);',
|
|
233
|
-
output: 'expect("a string").rejects.toBeDefined();',
|
|
234
|
-
errors: [{
|
|
235
|
-
messageId: 'useToBeDefined',
|
|
236
|
-
column: 32,
|
|
237
|
-
line: 1
|
|
238
|
-
}]
|
|
239
|
-
}, {
|
|
240
|
-
code: 'expect("a string").rejects.not["toBe"](undefined);',
|
|
241
|
-
output: 'expect("a string").rejects[\'toBeDefined\']();',
|
|
242
|
-
errors: [{
|
|
243
|
-
messageId: 'useToBeDefined',
|
|
244
|
-
column: 32,
|
|
245
|
-
line: 1
|
|
246
|
-
}]
|
|
247
|
-
}, {
|
|
248
|
-
code: 'expect("a string").not.toEqual(undefined);',
|
|
249
|
-
output: 'expect("a string").toBeDefined();',
|
|
250
|
-
errors: [{
|
|
251
|
-
messageId: 'useToBeDefined',
|
|
252
|
-
column: 24,
|
|
253
|
-
line: 1
|
|
254
|
-
}]
|
|
255
|
-
}, {
|
|
256
|
-
code: 'expect("a string").not.toStrictEqual(undefined);',
|
|
257
|
-
output: 'expect("a string").toBeDefined();',
|
|
258
|
-
errors: [{
|
|
259
|
-
messageId: 'useToBeDefined',
|
|
260
|
-
column: 24,
|
|
261
|
-
line: 1
|
|
262
|
-
}]
|
|
263
|
-
}]
|
|
264
|
-
});
|
|
265
|
-
ruleTester.run('prefer-to-be: NaN', _preferToBe.default, {
|
|
266
|
-
valid: ['expect(NaN).toBeNaN();', 'expect(true).not.toBeNaN();', 'expect({}).toEqual({});', 'expect(something).toBe()', 'expect(something).toBe(somethingElse)', 'expect(something).toEqual(somethingElse)', 'expect(something).not.toBe(somethingElse)', 'expect(something).not.toEqual(somethingElse)', 'expect(undefined).toBe', 'expect("something");'],
|
|
267
|
-
invalid: [{
|
|
268
|
-
code: 'expect(NaN).toBe(NaN);',
|
|
269
|
-
output: 'expect(NaN).toBeNaN();',
|
|
270
|
-
errors: [{
|
|
271
|
-
messageId: 'useToBeNaN',
|
|
272
|
-
column: 13,
|
|
273
|
-
line: 1
|
|
274
|
-
}]
|
|
275
|
-
}, {
|
|
276
|
-
code: 'expect(NaN).toEqual(NaN);',
|
|
277
|
-
output: 'expect(NaN).toBeNaN();',
|
|
278
|
-
errors: [{
|
|
279
|
-
messageId: 'useToBeNaN',
|
|
280
|
-
column: 13,
|
|
281
|
-
line: 1
|
|
282
|
-
}]
|
|
283
|
-
}, {
|
|
284
|
-
code: 'expect(NaN).toStrictEqual(NaN);',
|
|
285
|
-
output: 'expect(NaN).toBeNaN();',
|
|
286
|
-
errors: [{
|
|
287
|
-
messageId: 'useToBeNaN',
|
|
288
|
-
column: 13,
|
|
289
|
-
line: 1
|
|
290
|
-
}]
|
|
291
|
-
}, {
|
|
292
|
-
code: 'expect("a string").not.toBe(NaN);',
|
|
293
|
-
output: 'expect("a string").not.toBeNaN();',
|
|
294
|
-
errors: [{
|
|
295
|
-
messageId: 'useToBeNaN',
|
|
296
|
-
column: 24,
|
|
297
|
-
line: 1
|
|
298
|
-
}]
|
|
299
|
-
}, {
|
|
300
|
-
code: 'expect("a string").rejects.not.toBe(NaN);',
|
|
301
|
-
output: 'expect("a string").rejects.not.toBeNaN();',
|
|
302
|
-
errors: [{
|
|
303
|
-
messageId: 'useToBeNaN',
|
|
304
|
-
column: 32,
|
|
305
|
-
line: 1
|
|
306
|
-
}]
|
|
307
|
-
}, {
|
|
308
|
-
code: 'expect("a string")["rejects"].not.toBe(NaN);',
|
|
309
|
-
output: 'expect("a string")["rejects"].not.toBeNaN();',
|
|
310
|
-
errors: [{
|
|
311
|
-
messageId: 'useToBeNaN',
|
|
312
|
-
column: 35,
|
|
313
|
-
line: 1
|
|
314
|
-
}]
|
|
315
|
-
}, {
|
|
316
|
-
code: 'expect("a string").not.toEqual(NaN);',
|
|
317
|
-
output: 'expect("a string").not.toBeNaN();',
|
|
318
|
-
errors: [{
|
|
319
|
-
messageId: 'useToBeNaN',
|
|
320
|
-
column: 24,
|
|
321
|
-
line: 1
|
|
322
|
-
}]
|
|
323
|
-
}, {
|
|
324
|
-
code: 'expect("a string").not.toStrictEqual(NaN);',
|
|
325
|
-
output: 'expect("a string").not.toBeNaN();',
|
|
326
|
-
errors: [{
|
|
327
|
-
messageId: 'useToBeNaN',
|
|
328
|
-
column: 24,
|
|
329
|
-
line: 1
|
|
330
|
-
}]
|
|
331
|
-
}]
|
|
332
|
-
});
|
|
333
|
-
ruleTester.run('prefer-to-be: undefined vs defined', _preferToBe.default, {
|
|
334
|
-
valid: ['expect(NaN).toBeNaN();', 'expect(true).not.toBeNaN();', 'expect({}).toEqual({});', 'expect(something).toBe()', 'expect(something).toBe(somethingElse)', 'expect(something).toEqual(somethingElse)', 'expect(something).not.toBe(somethingElse)', 'expect(something).not.toEqual(somethingElse)', 'expect(undefined).toBe', 'expect("something");'],
|
|
335
|
-
invalid: [{
|
|
336
|
-
code: 'expect(undefined).not.toBeDefined();',
|
|
337
|
-
output: 'expect(undefined).toBeUndefined();',
|
|
338
|
-
errors: [{
|
|
339
|
-
messageId: 'useToBeUndefined',
|
|
340
|
-
column: 23,
|
|
341
|
-
line: 1
|
|
342
|
-
}]
|
|
343
|
-
}, {
|
|
344
|
-
code: 'expect(undefined).resolves.not.toBeDefined();',
|
|
345
|
-
output: 'expect(undefined).resolves.toBeUndefined();',
|
|
346
|
-
errors: [{
|
|
347
|
-
messageId: 'useToBeUndefined',
|
|
348
|
-
column: 32,
|
|
349
|
-
line: 1
|
|
350
|
-
}]
|
|
351
|
-
}, {
|
|
352
|
-
code: 'expect(undefined).resolves.toBe(undefined);',
|
|
353
|
-
output: 'expect(undefined).resolves.toBeUndefined();',
|
|
354
|
-
errors: [{
|
|
355
|
-
messageId: 'useToBeUndefined',
|
|
356
|
-
column: 28,
|
|
357
|
-
line: 1
|
|
358
|
-
}]
|
|
359
|
-
}, {
|
|
360
|
-
code: 'expect("a string").not.toBeUndefined();',
|
|
361
|
-
output: 'expect("a string").toBeDefined();',
|
|
362
|
-
errors: [{
|
|
363
|
-
messageId: 'useToBeDefined',
|
|
364
|
-
column: 24,
|
|
365
|
-
line: 1
|
|
366
|
-
}]
|
|
367
|
-
}, {
|
|
368
|
-
code: 'expect("a string").rejects.not.toBeUndefined();',
|
|
369
|
-
output: 'expect("a string").rejects.toBeDefined();',
|
|
370
|
-
errors: [{
|
|
371
|
-
messageId: 'useToBeDefined',
|
|
372
|
-
column: 32,
|
|
373
|
-
line: 1
|
|
374
|
-
}]
|
|
375
|
-
}]
|
|
376
|
-
});
|
|
377
|
-
new _utils.TSESLint.RuleTester({
|
|
378
|
-
parser: require.resolve('@typescript-eslint/parser')
|
|
379
|
-
}).run('prefer-to-be: typescript edition', _preferToBe.default, {
|
|
380
|
-
valid: ["(expect('Model must be bound to an array if the multiple property is true') as any).toHaveBeenTipped()"],
|
|
381
|
-
invalid: [{
|
|
382
|
-
code: 'expect(null).toEqual(1 as unknown as string as unknown as any);',
|
|
383
|
-
output: 'expect(null).toBe(1 as unknown as string as unknown as any);',
|
|
384
|
-
errors: [{
|
|
385
|
-
messageId: 'useToBe',
|
|
386
|
-
column: 14,
|
|
387
|
-
line: 1
|
|
388
|
-
}]
|
|
389
|
-
}, {
|
|
390
|
-
code: 'expect(null).toEqual(-1 as unknown as string as unknown as any);',
|
|
391
|
-
output: 'expect(null).toBe(-1 as unknown as string as unknown as any);',
|
|
392
|
-
errors: [{
|
|
393
|
-
messageId: 'useToBe',
|
|
394
|
-
column: 14,
|
|
395
|
-
line: 1
|
|
396
|
-
}]
|
|
397
|
-
}, {
|
|
398
|
-
code: 'expect("a string").not.toStrictEqual("string" as number);',
|
|
399
|
-
output: 'expect("a string").not.toBe("string" as number);',
|
|
400
|
-
errors: [{
|
|
401
|
-
messageId: 'useToBe',
|
|
402
|
-
column: 24,
|
|
403
|
-
line: 1
|
|
404
|
-
}]
|
|
405
|
-
}, {
|
|
406
|
-
code: 'expect(null).toBe(null as unknown as string as unknown as any);',
|
|
407
|
-
output: 'expect(null).toBeNull();',
|
|
408
|
-
errors: [{
|
|
409
|
-
messageId: 'useToBeNull',
|
|
410
|
-
column: 14,
|
|
411
|
-
line: 1
|
|
412
|
-
}]
|
|
413
|
-
}, {
|
|
414
|
-
code: 'expect("a string").not.toEqual(null as number);',
|
|
415
|
-
output: 'expect("a string").not.toBeNull();',
|
|
416
|
-
errors: [{
|
|
417
|
-
messageId: 'useToBeNull',
|
|
418
|
-
column: 24,
|
|
419
|
-
line: 1
|
|
420
|
-
}]
|
|
421
|
-
}, {
|
|
422
|
-
code: 'expect(undefined).toBe(undefined as unknown as string as any);',
|
|
423
|
-
output: 'expect(undefined).toBeUndefined();',
|
|
424
|
-
errors: [{
|
|
425
|
-
messageId: 'useToBeUndefined',
|
|
426
|
-
column: 19,
|
|
427
|
-
line: 1
|
|
428
|
-
}]
|
|
429
|
-
}, {
|
|
430
|
-
code: 'expect("a string").toEqual(undefined as number);',
|
|
431
|
-
output: 'expect("a string").toBeUndefined();',
|
|
432
|
-
errors: [{
|
|
433
|
-
messageId: 'useToBeUndefined',
|
|
434
|
-
column: 20,
|
|
435
|
-
line: 1
|
|
436
|
-
}]
|
|
437
|
-
}]
|
|
438
|
-
});
|