eslint-plugin-jest 23.18.0 → 23.20.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/CHANGELOG.md +28 -0
- package/README.md +44 -42
- package/docs/rules/consistent-test-it.md +13 -13
- package/docs/rules/expect-expect.md +18 -7
- package/docs/rules/lowercase-name.md +5 -5
- package/docs/rules/no-alias-methods.md +1 -1
- package/docs/rules/no-duplicate-hooks.md +1 -1
- package/docs/rules/no-export.md +3 -4
- package/docs/rules/no-hooks.md +2 -2
- package/docs/rules/no-interpolation-in-snapshots.md +60 -0
- package/docs/rules/no-large-snapshots.md +47 -41
- package/docs/rules/no-standalone-expect.md +1 -1
- package/docs/rules/prefer-called-with.md +1 -1
- package/docs/rules/prefer-expect-assertions.md +5 -5
- package/docs/rules/prefer-hooks-on-top.md +16 -16
- package/docs/rules/prefer-inline-snapshots.md +2 -2
- package/docs/rules/prefer-to-be-null.md +1 -1
- package/docs/rules/prefer-to-be-undefined.md +1 -1
- package/docs/rules/prefer-to-have-length.md +2 -2
- package/docs/rules/prefer-todo.md +1 -1
- package/docs/rules/require-to-throw-message.md +13 -9
- package/docs/rules/require-top-level-describe.md +4 -4
- package/docs/rules/valid-expect-in-promise.md +2 -4
- package/docs/rules/valid-expect.md +28 -24
- package/docs/rules/valid-title.md +1 -1
- package/lib/rules/no-export.js +1 -1
- package/lib/rules/no-if.js +3 -1
- package/lib/rules/no-interpolation-in-snapshots.js +63 -0
- package/lib/rules/no-large-snapshots.js +20 -9
- package/lib/rules/no-mocks-import.js +2 -2
- package/lib/rules/no-standalone-expect.js +1 -1
- package/lib/rules/prefer-called-with.js +1 -1
- package/lib/rules/prefer-hooks-on-top.js +1 -1
- package/lib/rules/prefer-strict-equal.js +1 -1
- package/lib/rules/require-top-level-describe.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# [23.20.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.19.0...v23.20.0) (2020-07-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **no-large-snapshots:** deprecate `whitelistedSnapshots` for new name ([#632](https://github.com/jest-community/eslint-plugin-jest/issues/632)) ([706f5c2](https://github.com/jest-community/eslint-plugin-jest/commit/706f5c2bc54797f0f32178fab1d194d9a4309f70))
|
|
7
|
+
|
|
8
|
+
# [23.19.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.18.2...v23.19.0) (2020-07-27)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* create `no-interpolation-in-snapshots` rule ([#553](https://github.com/jest-community/eslint-plugin-jest/issues/553)) ([8d2c17c](https://github.com/jest-community/eslint-plugin-jest/commit/8d2c17c449841465630bea5269de677455ef9a8d))
|
|
14
|
+
|
|
15
|
+
## [23.18.2](https://github.com/jest-community/eslint-plugin-jest/compare/v23.18.1...v23.18.2) (2020-07-26)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **no-if:** report conditionals in call expressions ([4cfcf08](https://github.com/jest-community/eslint-plugin-jest/commit/4cfcf080893fbe89689bd4b283bb2f3ad09b19ff)), closes [#557](https://github.com/jest-community/eslint-plugin-jest/issues/557)
|
|
21
|
+
|
|
22
|
+
## [23.18.1](https://github.com/jest-community/eslint-plugin-jest/compare/v23.18.0...v23.18.1) (2020-07-26)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* **no-large-snapshots:** actually compare allowed name strings to name ([#625](https://github.com/jest-community/eslint-plugin-jest/issues/625)) ([622a08c](https://github.com/jest-community/eslint-plugin-jest/commit/622a08c86a37aa9490af20b488bd23246b8be752))
|
|
28
|
+
|
|
1
29
|
# [23.18.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.17.1...v23.18.0) (2020-07-05)
|
|
2
30
|
|
|
3
31
|
|
package/README.md
CHANGED
|
@@ -46,7 +46,8 @@ Then configure the rules you want to use under the rules section.
|
|
|
46
46
|
}
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
You can also
|
|
49
|
+
You can also tell ESLint about the environment variables provided by Jest by
|
|
50
|
+
doing:
|
|
50
51
|
|
|
51
52
|
```json
|
|
52
53
|
{
|
|
@@ -127,47 +128,48 @@ installations requiring long-term consistency.
|
|
|
127
128
|
|
|
128
129
|
<!-- begin rules list -->
|
|
129
130
|
|
|
130
|
-
| Rule
|
|
131
|
-
|
|
|
132
|
-
| [consistent-test-it](docs/rules/consistent-test-it.md)
|
|
133
|
-
| [expect-expect](docs/rules/expect-expect.md)
|
|
134
|
-
| [lowercase-name](docs/rules/lowercase-name.md)
|
|
135
|
-
| [no-alias-methods](docs/rules/no-alias-methods.md)
|
|
136
|
-
| [no-commented-out-tests](docs/rules/no-commented-out-tests.md)
|
|
137
|
-
| [no-conditional-expect](docs/rules/no-conditional-expect.md)
|
|
138
|
-
| [no-deprecated-functions](docs/rules/no-deprecated-functions.md)
|
|
139
|
-
| [no-disabled-tests](docs/rules/no-disabled-tests.md)
|
|
140
|
-
| [no-duplicate-hooks](docs/rules/no-duplicate-hooks.md)
|
|
141
|
-
| [no-export](docs/rules/no-export.md)
|
|
142
|
-
| [no-focused-tests](docs/rules/no-focused-tests.md)
|
|
143
|
-
| [no-hooks](docs/rules/no-hooks.md)
|
|
144
|
-
| [no-identical-title](docs/rules/no-identical-title.md)
|
|
145
|
-
| [no-if](docs/rules/no-if.md)
|
|
146
|
-
| [no-
|
|
147
|
-
| [no-
|
|
148
|
-
| [no-
|
|
149
|
-
| [no-
|
|
150
|
-
| [no-
|
|
151
|
-
| [no-
|
|
152
|
-
| [no-
|
|
153
|
-
| [no-test-
|
|
154
|
-
| [no-test-
|
|
155
|
-
| [
|
|
156
|
-
| [prefer-
|
|
157
|
-
| [prefer-
|
|
158
|
-
| [prefer-
|
|
159
|
-
| [prefer-
|
|
160
|
-
| [prefer-
|
|
161
|
-
| [prefer-to-be-
|
|
162
|
-
| [prefer-to-
|
|
163
|
-
| [prefer-to-
|
|
164
|
-
| [prefer-
|
|
165
|
-
| [
|
|
166
|
-
| [require-
|
|
167
|
-
| [
|
|
168
|
-
| [valid-
|
|
169
|
-
| [valid-expect
|
|
170
|
-
| [valid-
|
|
131
|
+
| Rule | Description | Configurations | Fixable |
|
|
132
|
+
| ---------------------------------------------------------------------------- | --------------------------------------------------------------- | ---------------- | ------------ |
|
|
133
|
+
| [consistent-test-it](docs/rules/consistent-test-it.md) | Have control over `test` and `it` usages | | ![fixable][] |
|
|
134
|
+
| [expect-expect](docs/rules/expect-expect.md) | Enforce assertion to be made in a test body | ![recommended][] | |
|
|
135
|
+
| [lowercase-name](docs/rules/lowercase-name.md) | Enforce lowercase test names | | ![fixable][] |
|
|
136
|
+
| [no-alias-methods](docs/rules/no-alias-methods.md) | Disallow alias methods | ![style][] | ![fixable][] |
|
|
137
|
+
| [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | Disallow commented out tests | ![recommended][] | |
|
|
138
|
+
| [no-conditional-expect](docs/rules/no-conditional-expect.md) | Prevent calling `expect` conditionally | | |
|
|
139
|
+
| [no-deprecated-functions](docs/rules/no-deprecated-functions.md) | Disallow use of deprecated functions | | ![fixable][] |
|
|
140
|
+
| [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | ![recommended][] | |
|
|
141
|
+
| [no-duplicate-hooks](docs/rules/no-duplicate-hooks.md) | Disallow duplicate setup and teardown hooks | | |
|
|
142
|
+
| [no-export](docs/rules/no-export.md) | Disallow using `exports` in files containing tests | ![recommended][] | |
|
|
143
|
+
| [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ![recommended][] | ![fixable][] |
|
|
144
|
+
| [no-hooks](docs/rules/no-hooks.md) | Disallow setup and teardown hooks | | |
|
|
145
|
+
| [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | ![recommended][] | |
|
|
146
|
+
| [no-if](docs/rules/no-if.md) | Disallow conditional logic | | |
|
|
147
|
+
| [no-interpolation-in-snapshots](docs/rules/no-interpolation-in-snapshots.md) | Disallow string interpolation inside snapshots | | |
|
|
148
|
+
| [no-jasmine-globals](docs/rules/no-jasmine-globals.md) | Disallow Jasmine globals | ![recommended][] | ![fixable][] |
|
|
149
|
+
| [no-jest-import](docs/rules/no-jest-import.md) | Disallow importing Jest | ![recommended][] | |
|
|
150
|
+
| [no-large-snapshots](docs/rules/no-large-snapshots.md) | disallow large snapshots | | |
|
|
151
|
+
| [no-mocks-import](docs/rules/no-mocks-import.md) | Disallow manually importing from `__mocks__` | ![recommended][] | |
|
|
152
|
+
| [no-restricted-matchers](docs/rules/no-restricted-matchers.md) | Disallow specific matchers & modifiers | | |
|
|
153
|
+
| [no-standalone-expect](docs/rules/no-standalone-expect.md) | Disallow using `expect` outside of `it` or `test` blocks | ![recommended][] | |
|
|
154
|
+
| [no-test-callback](docs/rules/no-test-callback.md) | Avoid using a callback in asynchronous tests | ![recommended][] | ![suggest][] |
|
|
155
|
+
| [no-test-prefixes](docs/rules/no-test-prefixes.md) | Use `.only` and `.skip` over `f` and `x` | ![recommended][] | ![fixable][] |
|
|
156
|
+
| [no-test-return-statement](docs/rules/no-test-return-statement.md) | Disallow explicitly returning from tests | | |
|
|
157
|
+
| [prefer-called-with](docs/rules/prefer-called-with.md) | Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()` | | |
|
|
158
|
+
| [prefer-expect-assertions](docs/rules/prefer-expect-assertions.md) | Suggest using `expect.assertions()` OR `expect.hasAssertions()` | | ![suggest][] |
|
|
159
|
+
| [prefer-hooks-on-top](docs/rules/prefer-hooks-on-top.md) | Suggest having hooks before any test cases | | |
|
|
160
|
+
| [prefer-spy-on](docs/rules/prefer-spy-on.md) | Suggest using `jest.spyOn()` | | ![fixable][] |
|
|
161
|
+
| [prefer-strict-equal](docs/rules/prefer-strict-equal.md) | Suggest using `toStrictEqual()` | | ![suggest][] |
|
|
162
|
+
| [prefer-to-be-null](docs/rules/prefer-to-be-null.md) | Suggest using `toBeNull()` | ![style][] | ![fixable][] |
|
|
163
|
+
| [prefer-to-be-undefined](docs/rules/prefer-to-be-undefined.md) | Suggest using `toBeUndefined()` | ![style][] | ![fixable][] |
|
|
164
|
+
| [prefer-to-contain](docs/rules/prefer-to-contain.md) | Suggest using `toContain()` | ![style][] | ![fixable][] |
|
|
165
|
+
| [prefer-to-have-length](docs/rules/prefer-to-have-length.md) | Suggest using `toHaveLength()` | ![style][] | ![fixable][] |
|
|
166
|
+
| [prefer-todo](docs/rules/prefer-todo.md) | Suggest using `test.todo` | | ![fixable][] |
|
|
167
|
+
| [require-to-throw-message](docs/rules/require-to-throw-message.md) | Require a message for `toThrow()` | | |
|
|
168
|
+
| [require-top-level-describe](docs/rules/require-top-level-describe.md) | Require test cases and hooks to be inside a `describe` block | | |
|
|
169
|
+
| [valid-describe](docs/rules/valid-describe.md) | Enforce valid `describe()` callback | ![recommended][] | |
|
|
170
|
+
| [valid-expect](docs/rules/valid-expect.md) | Enforce valid `expect()` usage | ![recommended][] | |
|
|
171
|
+
| [valid-expect-in-promise](docs/rules/valid-expect-in-promise.md) | Enforce having return statement when testing with promises | ![recommended][] | |
|
|
172
|
+
| [valid-title](docs/rules/valid-title.md) | Enforce valid titles | | ![fixable][] |
|
|
171
173
|
|
|
172
174
|
<!-- end rules list -->
|
|
173
175
|
|
|
@@ -12,18 +12,18 @@ This rule gives you control over the usage of these keywords in your codebase.
|
|
|
12
12
|
|
|
13
13
|
This rule can be configured as follows
|
|
14
14
|
|
|
15
|
-
```
|
|
15
|
+
```json5
|
|
16
16
|
{
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
},
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
fn: {
|
|
20
|
+
enum: ['it', 'test'],
|
|
21
|
+
},
|
|
22
|
+
withinDescribe: {
|
|
23
|
+
enum: ['it', 'test'],
|
|
25
24
|
},
|
|
26
|
-
|
|
25
|
+
},
|
|
26
|
+
additionalProperties: false,
|
|
27
27
|
}
|
|
28
28
|
```
|
|
29
29
|
|
|
@@ -33,7 +33,7 @@ Decides whether to use `test` or `it`.
|
|
|
33
33
|
|
|
34
34
|
#### withinDescribe
|
|
35
35
|
|
|
36
|
-
Decides whether to use `test` or `it` within a describe scope.
|
|
36
|
+
Decides whether to use `test` or `it` within a `describe` scope.
|
|
37
37
|
|
|
38
38
|
```js
|
|
39
39
|
/*eslint jest/consistent-test-it: ["error", {"fn": "test"}]*/
|
|
@@ -71,8 +71,8 @@ describe('foo', function() {
|
|
|
71
71
|
|
|
72
72
|
### Default configuration
|
|
73
73
|
|
|
74
|
-
The default configuration forces top
|
|
75
|
-
nested within describe to use `it`.
|
|
74
|
+
The default configuration forces all top-level tests to use `test` and all tests
|
|
75
|
+
nested within `describe` to use `it`.
|
|
76
76
|
|
|
77
77
|
```js
|
|
78
78
|
/*eslint jest/consistent-test-it: ["error"]*/
|
|
@@ -42,9 +42,9 @@ it('should work with callbacks/async', () => {
|
|
|
42
42
|
|
|
43
43
|
### `assertFunctionNames`
|
|
44
44
|
|
|
45
|
-
This array option
|
|
46
|
-
names can use wildcards
|
|
47
|
-
`request.*.expect*`
|
|
45
|
+
This array option specifies the names of functions that should be considered to
|
|
46
|
+
be asserting functions. Function names can use wildcards i.e `request.*.expect`,
|
|
47
|
+
`request.**.expect`, `request.*.expect*`
|
|
48
48
|
|
|
49
49
|
Examples of **incorrect** code for the `{ "assertFunctionNames": ["expect"] }`
|
|
50
50
|
option:
|
|
@@ -55,11 +55,11 @@ option:
|
|
|
55
55
|
import { expectSaga } from 'redux-saga-test-plan';
|
|
56
56
|
import { addSaga } from '../src/sagas';
|
|
57
57
|
|
|
58
|
-
test('returns sum', () =>
|
|
58
|
+
test('returns sum', () => {
|
|
59
59
|
expectSaga(addSaga, 1, 1)
|
|
60
60
|
.returns(2)
|
|
61
61
|
.run();
|
|
62
|
-
);
|
|
62
|
+
});
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
Examples of **correct** code for the
|
|
@@ -71,11 +71,22 @@ Examples of **correct** code for the
|
|
|
71
71
|
import { expectSaga } from 'redux-saga-test-plan';
|
|
72
72
|
import { addSaga } from '../src/sagas';
|
|
73
73
|
|
|
74
|
-
test('returns sum', () =>
|
|
74
|
+
test('returns sum', () => {
|
|
75
75
|
expectSaga(addSaga, 1, 1)
|
|
76
76
|
.returns(2)
|
|
77
77
|
.run();
|
|
78
|
-
);
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Since the string is compiled into aa regular expression, you'll need to escape
|
|
82
|
+
special characters such as `$` with a double backslash:
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect\\$"] }] */
|
|
86
|
+
|
|
87
|
+
it('is money-like', () => {
|
|
88
|
+
expect$(1.0);
|
|
89
|
+
});
|
|
79
90
|
```
|
|
80
91
|
|
|
81
92
|
Examples of **correct** code for working with the HTTP assertions library
|
|
@@ -37,8 +37,8 @@ it('adds 1 + 2 to equal 3', () => {
|
|
|
37
37
|
|
|
38
38
|
### `ignore`
|
|
39
39
|
|
|
40
|
-
This array option
|
|
41
|
-
|
|
40
|
+
This array option controls which Jest functions are checked by this rule. There
|
|
41
|
+
are three possible values:
|
|
42
42
|
|
|
43
43
|
- `"describe"`
|
|
44
44
|
- `"test"`
|
|
@@ -73,9 +73,9 @@ it('Uppercase description');
|
|
|
73
73
|
|
|
74
74
|
### `allowedPrefixes`
|
|
75
75
|
|
|
76
|
-
This array option
|
|
77
|
-
This can be useful when writing tests for api endpoints, where
|
|
78
|
-
prefix with the HTTP method.
|
|
76
|
+
This array option allows specifying prefixes which contain capitals that titles
|
|
77
|
+
can start with. This can be useful when writing tests for api endpoints, where
|
|
78
|
+
you'd like to prefix with the HTTP method.
|
|
79
79
|
|
|
80
80
|
By default, nothing is allowed (the equivalent of `{ "allowedPrefixes": [] }`).
|
|
81
81
|
|
package/docs/rules/no-export.md
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Disallow using `exports` in files containing tests (`no-export`)
|
|
2
2
|
|
|
3
|
-
Prevents exports
|
|
4
|
-
rule will prevent exports.
|
|
3
|
+
Prevents using `exports` if a file has one or more tests in it.
|
|
5
4
|
|
|
6
5
|
## Rule Details
|
|
7
6
|
|
|
8
7
|
This rule aims to eliminate duplicate runs of tests by exporting things from
|
|
9
8
|
test files. If you import from a test file, then all the tests in that file will
|
|
10
9
|
be run in each imported instance, so bottom line, don't export from a test, but
|
|
11
|
-
instead move helper functions into a
|
|
10
|
+
instead move helper functions into a separate file when they need to be shared
|
|
12
11
|
across tests.
|
|
13
12
|
|
|
14
13
|
Examples of **incorrect** code for this rule:
|
package/docs/rules/no-hooks.md
CHANGED
|
@@ -101,8 +101,8 @@ describe('foo', () => {
|
|
|
101
101
|
|
|
102
102
|
### `allow`
|
|
103
103
|
|
|
104
|
-
This array option
|
|
105
|
-
|
|
104
|
+
This array option controls which Jest hooks are checked by this rule. There are
|
|
105
|
+
four possible values:
|
|
106
106
|
|
|
107
107
|
- `"beforeAll"`
|
|
108
108
|
- `"beforeEach"`
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Disallow string interpolation inside snapshots (`no-interpolation-in-snapshots`)
|
|
2
|
+
|
|
3
|
+
Prevents the use of string interpolations in snapshots.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
Interpolation prevents snapshots from being updated. Instead, properties should
|
|
8
|
+
be overloaded with a matcher by using
|
|
9
|
+
[property matchers](https://jestjs.io/docs/en/snapshot-testing#property-matchers).
|
|
10
|
+
|
|
11
|
+
Examples of **incorrect** code for this rule:
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
expect(something).toMatchInlineSnapshot(
|
|
15
|
+
`Object {
|
|
16
|
+
property: ${interpolated}
|
|
17
|
+
}`,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
expect(something).toMatchInlineSnapshot(
|
|
21
|
+
{ other: expect.any(Number) },
|
|
22
|
+
`Object {
|
|
23
|
+
other: Any<Number>,
|
|
24
|
+
property: ${interpolated}
|
|
25
|
+
}`,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expect(errorThrowingFunction).toThrowErrorMatchingInlineSnapshot(
|
|
29
|
+
`${interpolated}`,
|
|
30
|
+
);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Examples of **correct** code for this rule:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
expect(something).toMatchInlineSnapshot();
|
|
37
|
+
|
|
38
|
+
expect(something).toMatchInlineSnapshot(
|
|
39
|
+
`Object {
|
|
40
|
+
property: 1
|
|
41
|
+
}`,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(something).toMatchInlineSnapshot(
|
|
45
|
+
{ property: expect.any(Date) },
|
|
46
|
+
`Object {
|
|
47
|
+
property: Any<Date>
|
|
48
|
+
}`,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
expect(errorThrowingFunction).toThrowErrorMatchingInlineSnapshot();
|
|
52
|
+
|
|
53
|
+
expect(errorThrowingFunction).toThrowErrorMatchingInlineSnapshot(
|
|
54
|
+
`Error Message`,
|
|
55
|
+
);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## When Not To Use It
|
|
59
|
+
|
|
60
|
+
Don't use this rule on non-jest test files.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# disallow large snapshots (`no-large-snapshots`)
|
|
2
2
|
|
|
3
3
|
When using Jest's snapshot capability one should be mindful of the size of
|
|
4
|
-
created snapshots. As a best practice snapshots should be limited in
|
|
5
|
-
order to be more manageable and reviewable. A stored snapshot is only as
|
|
6
|
-
its review and as such keeping it short, sweet, and readable is
|
|
7
|
-
allow for thorough reviews.
|
|
4
|
+
created snapshots. As a general best practice snapshots should be limited in
|
|
5
|
+
size in order to be more manageable and reviewable. A stored snapshot is only as
|
|
6
|
+
good as its review and as such keeping it short, sweet, and readable is
|
|
7
|
+
important to allow for thorough reviews.
|
|
8
8
|
|
|
9
9
|
## Usage
|
|
10
10
|
|
|
@@ -15,9 +15,11 @@ you should set `parserOptions` in your config to at least allow ES2015 in order
|
|
|
15
15
|
to use this rule:
|
|
16
16
|
|
|
17
17
|
```js
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
module.exports = {
|
|
19
|
+
parserOptions: {
|
|
20
|
+
ecmaVersion: 2015,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
21
23
|
```
|
|
22
24
|
|
|
23
25
|
## Rule Details
|
|
@@ -104,11 +106,11 @@ snapshot:
|
|
|
104
106
|
In an `eslintrc` file:
|
|
105
107
|
|
|
106
108
|
```json
|
|
107
|
-
|
|
109
|
+
{
|
|
108
110
|
"rules": {
|
|
109
111
|
"jest/no-large-snapshots": ["warn", { "maxSize": 12, "inlineMaxSize": 6 }]
|
|
110
112
|
}
|
|
111
|
-
|
|
113
|
+
}
|
|
112
114
|
```
|
|
113
115
|
|
|
114
116
|
Max number of lines allowed could be defined by snapshot type (Inline and
|
|
@@ -119,48 +121,52 @@ size and `maxSize` for
|
|
|
119
121
|
If only `maxSize` is provided on options, the value of `maxSize` will be used to
|
|
120
122
|
both snapshot types (Inline and External).
|
|
121
123
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
Since `eslint-disable` comments are not preserved by Jest when updating
|
|
125
|
+
snapshots, you can use the `allowedSnapshots` option to have specific snapshots
|
|
126
|
+
allowed regardless of their size.
|
|
127
|
+
|
|
128
|
+
This option takes a map, with the key being the absolute filepath to a snapshot
|
|
129
|
+
file, and the value an array of values made up of strings and regular
|
|
130
|
+
expressions to compare to the names of the snapshots in the `.snap` file when
|
|
131
|
+
checking if the snapshots size should be allowed.
|
|
132
|
+
|
|
133
|
+
Note that regular expressions can only be passed in via `.eslintrc.js` as
|
|
134
|
+
instances of `RegExp`.
|
|
128
135
|
|
|
129
136
|
In an `.eslintrc.js` file:
|
|
130
137
|
|
|
131
138
|
```javascript
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
module.exports = {
|
|
140
|
+
rules: {
|
|
141
|
+
'jest/no-large-snapshots': [
|
|
142
|
+
'error',
|
|
136
143
|
{
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
+
allowedSnapshots: {
|
|
145
|
+
'/path/to/file.js.snap': ['snapshot name 1', /a big snapshot \d+/],
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
};
|
|
144
151
|
```
|
|
145
152
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
whitelisted snapshots in a file called `allowed-snaps.js` which stores them as
|
|
149
|
-
relative paths. To convert them to absolute paths you can do something like the
|
|
150
|
-
following:
|
|
153
|
+
Since absolute paths are typically not very portable, you can use the builtin
|
|
154
|
+
`path.resolve` function to expand relative paths into absolutes like so:
|
|
151
155
|
|
|
152
156
|
```javascript
|
|
153
157
|
const path = require('path');
|
|
154
|
-
const {mapKeys} = require('lodash');
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const allowedSnapshots = require('./allowed-snaps.js');
|
|
158
|
-
const whitelistedSnapshots = mapKeys(allowedSnapshots, (val, file) => path.resolve(__dirname, file));
|
|
159
158
|
|
|
160
|
-
|
|
159
|
+
module.exports = {
|
|
161
160
|
rules: {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
'jest/no-large-snapshots': [
|
|
162
|
+
'error',
|
|
163
|
+
{
|
|
164
|
+
allowedSnapshots: {
|
|
165
|
+
[path.resolve('test/__snapshots__/get.js.snap')]: ['full request'],
|
|
166
|
+
[path.resolve('test/__snapshots__/put.js.snap')]: ['full request'],
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
};
|
|
166
172
|
```
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Disallow using `expect` outside of `it` or `test` blocks (`no-standalone-expect`)
|
|
2
2
|
|
|
3
3
|
Prevents `expect` statements outside of a `test` or `it` block. An `expect`
|
|
4
4
|
within a helper function (but outside of a `test` or `it` block) will not
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Suggest using `toBeCalledWith`
|
|
1
|
+
# Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()` (`prefer-called-with`)
|
|
2
2
|
|
|
3
3
|
The `toBeCalled()` matcher is used to assert that a mock function has been
|
|
4
4
|
called one or more times, without checking the arguments passed. The assertion
|
|
@@ -32,13 +32,13 @@ test('my test', () => {
|
|
|
32
32
|
The following patterns are considered warnings:
|
|
33
33
|
|
|
34
34
|
```js
|
|
35
|
-
test(
|
|
36
|
-
expect.assertions(
|
|
37
|
-
expect(someThing()).toEqual(
|
|
35
|
+
test('my test', () => {
|
|
36
|
+
expect.assertions('1');
|
|
37
|
+
expect(someThing()).toEqual('foo');
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
test(
|
|
41
|
-
expect
|
|
40
|
+
test('my test', () => {
|
|
41
|
+
expect(someThing()).toEqual('foo');
|
|
42
42
|
});
|
|
43
43
|
```
|
|
44
44
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Suggest
|
|
1
|
+
# Suggest having hooks before any test cases (`prefer-hooks-on-top`)
|
|
2
2
|
|
|
3
3
|
All hooks should be defined before the start of the tests
|
|
4
4
|
|
|
@@ -9,37 +9,37 @@ Examples of **incorrect** code for this rule
|
|
|
9
9
|
```js
|
|
10
10
|
/* eslint jest/prefer-hooks-on-top: "error" */
|
|
11
11
|
|
|
12
|
-
describe(
|
|
12
|
+
describe('foo', () => {
|
|
13
13
|
beforeEach(() => {
|
|
14
14
|
//some hook code
|
|
15
15
|
});
|
|
16
|
-
test(
|
|
16
|
+
test('bar', () => {
|
|
17
17
|
some_fn();
|
|
18
18
|
});
|
|
19
19
|
beforeAll(() => {
|
|
20
20
|
//some hook code
|
|
21
21
|
});
|
|
22
|
-
test(
|
|
22
|
+
test('bar', () => {
|
|
23
23
|
some_fn();
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
// Nested describe scenario
|
|
28
|
-
describe(
|
|
28
|
+
describe('foo', () => {
|
|
29
29
|
beforeAll(() => {
|
|
30
30
|
//some hook code
|
|
31
31
|
});
|
|
32
|
-
test(
|
|
32
|
+
test('bar', () => {
|
|
33
33
|
some_fn();
|
|
34
34
|
});
|
|
35
|
-
describe(
|
|
35
|
+
describe('inner_foo', () => {
|
|
36
36
|
beforeEach(() => {
|
|
37
37
|
//some hook code
|
|
38
38
|
});
|
|
39
|
-
test(
|
|
39
|
+
test('inner bar', () => {
|
|
40
40
|
some_fn();
|
|
41
41
|
});
|
|
42
|
-
test(
|
|
42
|
+
test('inner bar', () => {
|
|
43
43
|
some_fn();
|
|
44
44
|
});
|
|
45
45
|
beforeAll(() => {
|
|
@@ -48,7 +48,7 @@ describe("foo" () => {
|
|
|
48
48
|
afterAll(() => {
|
|
49
49
|
//some hook code
|
|
50
50
|
});
|
|
51
|
-
test(
|
|
51
|
+
test('inner bar', () => {
|
|
52
52
|
some_fn();
|
|
53
53
|
});
|
|
54
54
|
});
|
|
@@ -60,7 +60,7 @@ Examples of **correct** code for this rule
|
|
|
60
60
|
```js
|
|
61
61
|
/* eslint jest/prefer-hooks-on-top: "error" */
|
|
62
62
|
|
|
63
|
-
describe(
|
|
63
|
+
describe('foo', () => {
|
|
64
64
|
beforeEach(() => {
|
|
65
65
|
//some hook code
|
|
66
66
|
});
|
|
@@ -71,24 +71,24 @@ describe("foo" () => {
|
|
|
71
71
|
afterEach(() => {
|
|
72
72
|
//some hook code
|
|
73
73
|
});
|
|
74
|
-
test(
|
|
74
|
+
test('bar', () => {
|
|
75
75
|
some_fn();
|
|
76
76
|
});
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
// Nested describe scenario
|
|
80
|
-
describe(
|
|
80
|
+
describe('foo', () => {
|
|
81
81
|
beforeEach(() => {
|
|
82
82
|
//some hook code
|
|
83
83
|
});
|
|
84
|
-
test(
|
|
84
|
+
test('bar', () => {
|
|
85
85
|
some_fn();
|
|
86
86
|
});
|
|
87
|
-
describe(
|
|
87
|
+
describe('inner_foo', () => {
|
|
88
88
|
beforeEach(() => {
|
|
89
89
|
//some hook code
|
|
90
90
|
});
|
|
91
|
-
test(
|
|
91
|
+
test('inner bar', () => {
|
|
92
92
|
some_fn();
|
|
93
93
|
});
|
|
94
94
|
});
|
|
@@ -21,9 +21,9 @@ This rule has been deprecated in favor of
|
|
|
21
21
|
|
|
22
22
|
---
|
|
23
23
|
|
|
24
|
-
In order to make snapshot tests more
|
|
24
|
+
In order to make snapshot tests more manageable and reviewable
|
|
25
25
|
`toMatchInlineSnapshot()` and `toThrowErrorMatchingInlineSnapshot` should be
|
|
26
|
-
used to write the snapshots inline in the test file.
|
|
26
|
+
used to write the snapshots' inline in the test file.
|
|
27
27
|
|
|
28
28
|
## Rule details
|
|
29
29
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Suggest using `toHaveLength()` (`prefer-to-have-length`)
|
|
2
2
|
|
|
3
3
|
In order to have a better failure message, `toHaveLength()` should be used upon
|
|
4
|
-
asserting expectations on
|
|
4
|
+
asserting expectations on objects length property.
|
|
5
5
|
|
|
6
6
|
## Rule details
|
|
7
7
|
|
|
8
8
|
This rule triggers a warning if `toBe()`, `toEqual()` or `toStrictEqual()` is
|
|
9
|
-
used to assert
|
|
9
|
+
used to assert objects length property.
|
|
10
10
|
|
|
11
11
|
```js
|
|
12
12
|
expect(files.length).toBe(1);
|
|
@@ -5,7 +5,7 @@ will be highlighted in the summary output.
|
|
|
5
5
|
|
|
6
6
|
## Rule details
|
|
7
7
|
|
|
8
|
-
This rule triggers a warning if empty test
|
|
8
|
+
This rule triggers a warning if empty test cases are used without 'test.todo'.
|
|
9
9
|
|
|
10
10
|
```js
|
|
11
11
|
test('i need to write this test');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Require a message for `toThrow()` (`require-to-throw-message`)
|
|
2
2
|
|
|
3
|
-
`toThrow()
|
|
3
|
+
`toThrow()` (and its alias `toThrowError()`) is used to check if an error is
|
|
4
4
|
thrown by a function call, such as in `expect(() => a()).toThrow()`. However, if
|
|
5
5
|
no message is defined, then the test will pass for any thrown error. Requiring a
|
|
6
6
|
message ensures that the intended error is thrown.
|
|
@@ -15,23 +15,27 @@ an error message.
|
|
|
15
15
|
The following patterns are considered warnings:
|
|
16
16
|
|
|
17
17
|
```js
|
|
18
|
-
|
|
18
|
+
test('all the things', async () => {
|
|
19
|
+
expect(() => a()).toThrow();
|
|
19
20
|
|
|
20
|
-
expect(() => a()).toThrowError();
|
|
21
|
+
expect(() => a()).toThrowError();
|
|
21
22
|
|
|
22
|
-
await expect(a()).rejects.toThrow();
|
|
23
|
+
await expect(a()).rejects.toThrow();
|
|
23
24
|
|
|
24
|
-
await expect(a()).rejects.toThrowError();
|
|
25
|
+
await expect(a()).rejects.toThrowError();
|
|
26
|
+
});
|
|
25
27
|
```
|
|
26
28
|
|
|
27
29
|
The following patterns are not considered warnings:
|
|
28
30
|
|
|
29
31
|
```js
|
|
30
|
-
|
|
32
|
+
test('all the things', async () => {
|
|
33
|
+
expect(() => a()).toThrow('a');
|
|
31
34
|
|
|
32
|
-
expect(() => a()).toThrowError('a');
|
|
35
|
+
expect(() => a()).toThrowError('a');
|
|
33
36
|
|
|
34
|
-
await expect(a()).rejects.toThrow('a');
|
|
37
|
+
await expect(a()).rejects.toThrow('a');
|
|
35
38
|
|
|
36
|
-
await expect(a()).rejects.toThrowError('a');
|
|
39
|
+
await expect(a()).rejects.toThrowError('a');
|
|
40
|
+
});
|
|
37
41
|
```
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# Require
|
|
1
|
+
# Require test cases and hooks to be inside a `describe` block (`require-top-level-describe`)
|
|
2
2
|
|
|
3
3
|
Jest allows you to organise your test files the way you want it. However, the
|
|
4
4
|
more your codebase grows, the more it becomes hard to navigate in your test
|
|
5
|
-
files. This rule makes sure
|
|
6
|
-
|
|
5
|
+
files. This rule makes sure you provide at least a top-level `describe` block in
|
|
6
|
+
your test file.
|
|
7
7
|
|
|
8
8
|
## Rule Details
|
|
9
9
|
|
|
10
10
|
This rule triggers a warning if a test case (`test` and `it`) or a hook
|
|
11
11
|
(`beforeAll`, `beforeEach`, `afterEach`, `afterAll`) is not located in a
|
|
12
|
-
top-level describe block.
|
|
12
|
+
top-level `describe` block.
|
|
13
13
|
|
|
14
14
|
The following patterns are considered warnings:
|
|
15
15
|
|
|
@@ -5,10 +5,8 @@ promise
|
|
|
5
5
|
|
|
6
6
|
## Rule details
|
|
7
7
|
|
|
8
|
-
This rule
|
|
9
|
-
|
|
10
|
-
- test is having assertions in `then` or `catch` block of a promise
|
|
11
|
-
- and that promise is not returned from the test
|
|
8
|
+
This rule looks for tests that have assertions in `then` and `catch` methods on
|
|
9
|
+
promises that are not returned by the test.
|
|
12
10
|
|
|
13
11
|
### Default configuration
|
|
14
12
|
|
|
@@ -95,33 +95,37 @@ supported by `expect`, such as
|
|
|
95
95
|
The following patterns are considered warnings:
|
|
96
96
|
|
|
97
97
|
```js
|
|
98
|
-
|
|
99
|
-
expect()
|
|
100
|
-
expect('something'
|
|
101
|
-
expect('something');
|
|
102
|
-
|
|
103
|
-
expect(
|
|
104
|
-
expect(
|
|
105
|
-
expect(Promise.resolve('hello')).resolves
|
|
106
|
-
|
|
107
|
-
Promise.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
98
|
+
test('all the things', async () => {
|
|
99
|
+
expect();
|
|
100
|
+
expect().toEqual('something');
|
|
101
|
+
expect('something', 'else');
|
|
102
|
+
expect('something');
|
|
103
|
+
await expect('something');
|
|
104
|
+
expect(true).toBeDefined;
|
|
105
|
+
expect(Promise.resolve('hello')).resolves;
|
|
106
|
+
expect(Promise.resolve('hello')).resolves.toEqual('hello');
|
|
107
|
+
Promise.resolve(expect(Promise.resolve('hello')).resolves.toEqual('hello'));
|
|
108
|
+
Promise.all([
|
|
109
|
+
expect(Promise.resolve('hello')).resolves.toEqual('hello'),
|
|
110
|
+
expect(Promise.resolve('hi')).resolves.toEqual('hi'),
|
|
111
|
+
]);
|
|
112
|
+
});
|
|
111
113
|
```
|
|
112
114
|
|
|
113
115
|
The following patterns are not warnings:
|
|
114
116
|
|
|
115
117
|
```js
|
|
116
|
-
|
|
117
|
-
expect(
|
|
118
|
-
expect(
|
|
119
|
-
|
|
120
|
-
await Promise.resolve(
|
|
121
|
-
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
)
|
|
118
|
+
test('all the things', async () => {
|
|
119
|
+
expect('something').toEqual('something');
|
|
120
|
+
expect([1, 2, 3]).toEqual([1, 2, 3]);
|
|
121
|
+
expect(true).toBeDefined();
|
|
122
|
+
await expect(Promise.resolve('hello')).resolves.toEqual('hello');
|
|
123
|
+
await Promise.resolve(
|
|
124
|
+
expect(Promise.resolve('hello')).resolves.toEqual('hello'),
|
|
125
|
+
);
|
|
126
|
+
await Promise.all(
|
|
127
|
+
expect(Promise.resolve('hello')).resolves.toEqual('hello'),
|
|
128
|
+
expect(Promise.resolve('hi')).resolves.toEqual('hi'),
|
|
129
|
+
);
|
|
130
|
+
});
|
|
127
131
|
```
|
package/lib/rules/no-export.js
CHANGED
|
@@ -14,7 +14,7 @@ var _default = (0, _utils.createRule)({
|
|
|
14
14
|
meta: {
|
|
15
15
|
docs: {
|
|
16
16
|
category: 'Best Practices',
|
|
17
|
-
description: '
|
|
17
|
+
description: 'Disallow using `exports` in files containing tests',
|
|
18
18
|
recommended: 'error'
|
|
19
19
|
},
|
|
20
20
|
messages: {
|
package/lib/rules/no-if.js
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
|
9
|
+
|
|
10
|
+
var _utils = require("./utils");
|
|
11
|
+
|
|
12
|
+
var _default = (0, _utils.createRule)({
|
|
13
|
+
name: __filename,
|
|
14
|
+
meta: {
|
|
15
|
+
docs: {
|
|
16
|
+
category: 'Best Practices',
|
|
17
|
+
description: 'Disallow string interpolation inside snapshots',
|
|
18
|
+
recommended: false
|
|
19
|
+
},
|
|
20
|
+
messages: {
|
|
21
|
+
noInterpolation: 'Do not use string interpolation inside of snapshots'
|
|
22
|
+
},
|
|
23
|
+
schema: [],
|
|
24
|
+
type: 'problem'
|
|
25
|
+
},
|
|
26
|
+
defaultOptions: [],
|
|
27
|
+
|
|
28
|
+
create(context) {
|
|
29
|
+
return {
|
|
30
|
+
CallExpression(node) {
|
|
31
|
+
if (!(0, _utils.isExpectCall)(node)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const {
|
|
36
|
+
matcher
|
|
37
|
+
} = (0, _utils.parseExpectCall)(node);
|
|
38
|
+
|
|
39
|
+
if (!matcher) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (['toMatchInlineSnapshot', 'toThrowErrorMatchingInlineSnapshot'].includes(matcher.name)) {
|
|
44
|
+
var _matcher$arguments;
|
|
45
|
+
|
|
46
|
+
// Check all since the optional 'propertyMatchers' argument might be present
|
|
47
|
+
(_matcher$arguments = matcher.arguments) === null || _matcher$arguments === void 0 ? void 0 : _matcher$arguments.forEach(argument => {
|
|
48
|
+
if (argument.type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral && argument.expressions.length > 0) {
|
|
49
|
+
context.report({
|
|
50
|
+
messageId: 'noInterpolation',
|
|
51
|
+
node: argument
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
exports.default = _default;
|
|
@@ -19,36 +19,37 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
19
19
|
|
|
20
20
|
const reportOnViolation = (context, node, {
|
|
21
21
|
maxSize: lineLimit = 50,
|
|
22
|
-
whitelistedSnapshots = {}
|
|
22
|
+
whitelistedSnapshots = {},
|
|
23
|
+
allowedSnapshots = whitelistedSnapshots
|
|
23
24
|
}) => {
|
|
24
25
|
const startLine = node.loc.start.line;
|
|
25
26
|
const endLine = node.loc.end.line;
|
|
26
27
|
const lineCount = endLine - startLine;
|
|
27
|
-
const allPathsAreAbsolute = Object.keys(
|
|
28
|
+
const allPathsAreAbsolute = Object.keys(allowedSnapshots).every(_path.isAbsolute);
|
|
28
29
|
|
|
29
30
|
if (!allPathsAreAbsolute) {
|
|
30
|
-
throw new Error('All paths for
|
|
31
|
+
throw new Error('All paths for allowedSnapshots must be absolute. You can use JS config and `path.resolve`');
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
let
|
|
34
|
+
let isAllowed = false;
|
|
34
35
|
|
|
35
36
|
if (node.type === _experimentalUtils.AST_NODE_TYPES.ExpressionStatement && 'left' in node.expression && (0, _utils.isExpectMember)(node.expression.left)) {
|
|
36
37
|
const fileName = context.getFilename();
|
|
37
|
-
const
|
|
38
|
+
const allowedSnapshotsInFile = allowedSnapshots[fileName];
|
|
38
39
|
|
|
39
|
-
if (
|
|
40
|
+
if (allowedSnapshotsInFile) {
|
|
40
41
|
const snapshotName = (0, _utils.getAccessorValue)(node.expression.left.property);
|
|
41
|
-
|
|
42
|
+
isAllowed = allowedSnapshotsInFile.some(name => {
|
|
42
43
|
if (name instanceof RegExp) {
|
|
43
44
|
return name.test(snapshotName);
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
return snapshotName;
|
|
47
|
+
return snapshotName === name;
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
if (!
|
|
52
|
+
if (!isAllowed && lineCount > lineLimit) {
|
|
52
53
|
context.report({
|
|
53
54
|
messageId: lineLimit === 0 ? 'noSnapshot' : 'tooLongSnapshots',
|
|
54
55
|
data: {
|
|
@@ -82,6 +83,12 @@ var _default = (0, _utils.createRule)({
|
|
|
82
83
|
inlineMaxSize: {
|
|
83
84
|
type: 'number'
|
|
84
85
|
},
|
|
86
|
+
allowedSnapshots: {
|
|
87
|
+
type: 'object',
|
|
88
|
+
additionalProperties: {
|
|
89
|
+
type: 'array'
|
|
90
|
+
}
|
|
91
|
+
},
|
|
85
92
|
whitelistedSnapshots: {
|
|
86
93
|
type: 'object',
|
|
87
94
|
patternProperties: {
|
|
@@ -97,6 +104,10 @@ var _default = (0, _utils.createRule)({
|
|
|
97
104
|
defaultOptions: [{}],
|
|
98
105
|
|
|
99
106
|
create(context, [options]) {
|
|
107
|
+
if ('whitelistedSnapshots' in options) {
|
|
108
|
+
console.warn('jest/no-large-snapshots: the "whitelistedSnapshots" option has been renamed to "allowedSnapshots"');
|
|
109
|
+
}
|
|
110
|
+
|
|
100
111
|
if (context.getFilename().endsWith('.snap')) {
|
|
101
112
|
return {
|
|
102
113
|
ExpressionStatement(node) {
|
|
@@ -21,11 +21,11 @@ var _default = (0, _utils.createRule)({
|
|
|
21
21
|
type: 'problem',
|
|
22
22
|
docs: {
|
|
23
23
|
category: 'Best Practices',
|
|
24
|
-
description: 'Disallow manually importing from __mocks__
|
|
24
|
+
description: 'Disallow manually importing from `__mocks__`',
|
|
25
25
|
recommended: 'error'
|
|
26
26
|
},
|
|
27
27
|
messages: {
|
|
28
|
-
noManualImport: `Mocks should not be manually imported from a ${mocksDirName} directory. Instead use jest.mock and import from the original module path.`
|
|
28
|
+
noManualImport: `Mocks should not be manually imported from a ${mocksDirName} directory. Instead use \`jest.mock\` and import from the original module path.`
|
|
29
29
|
},
|
|
30
30
|
schema: []
|
|
31
31
|
},
|
|
@@ -45,7 +45,7 @@ var _default = (0, _utils.createRule)({
|
|
|
45
45
|
meta: {
|
|
46
46
|
docs: {
|
|
47
47
|
category: 'Best Practices',
|
|
48
|
-
description: '
|
|
48
|
+
description: 'Disallow using `expect` outside of `it` or `test` blocks',
|
|
49
49
|
recommended: 'error'
|
|
50
50
|
},
|
|
51
51
|
messages: {
|
|
@@ -12,7 +12,7 @@ var _default = (0, _utils.createRule)({
|
|
|
12
12
|
meta: {
|
|
13
13
|
docs: {
|
|
14
14
|
category: 'Best Practices',
|
|
15
|
-
description: 'Suggest using `toBeCalledWith()`
|
|
15
|
+
description: 'Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()`',
|
|
16
16
|
recommended: false
|
|
17
17
|
},
|
|
18
18
|
messages: {
|
|
@@ -12,7 +12,7 @@ var _default = (0, _utils.createRule)({
|
|
|
12
12
|
meta: {
|
|
13
13
|
docs: {
|
|
14
14
|
category: 'Best Practices',
|
|
15
|
-
description: '
|
|
15
|
+
description: 'Require test cases and hooks to be inside a `describe` block',
|
|
16
16
|
recommended: false
|
|
17
17
|
},
|
|
18
18
|
messages: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "23.
|
|
3
|
+
"version": "23.20.0",
|
|
4
4
|
"description": "Eslint rules for Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"prepack": "yarn build",
|
|
27
27
|
"prettylint": "prettylint docs/**/*.md README.md package.json",
|
|
28
28
|
"test": "jest",
|
|
29
|
-
"tools:
|
|
29
|
+
"tools:regenerate-docs": "ts-node -T tools/regenerate-docs",
|
|
30
30
|
"typecheck": "tsc -p ."
|
|
31
31
|
},
|
|
32
32
|
"husky": {
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"@babel/preset-typescript": "^7.3.3",
|
|
97
97
|
"@commitlint/cli": "^8.2.0",
|
|
98
98
|
"@commitlint/config-conventional": "^8.2.0",
|
|
99
|
-
"@schemastore/package": "^0.0.
|
|
99
|
+
"@schemastore/package": "^0.0.6",
|
|
100
100
|
"@semantic-release/changelog": "^3.0.5",
|
|
101
101
|
"@semantic-release/git": "^7.0.17",
|
|
102
102
|
"@types/dedent": "^0.7.0",
|