@depup/eslint-plugin-jest 29.15.1-depup.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/LICENSE +21 -0
- package/README.md +31 -0
- package/changes.json +10 -0
- package/docs/rules/consistent-test-it.md +96 -0
- package/docs/rules/expect-expect.md +152 -0
- package/docs/rules/max-expects.md +78 -0
- package/docs/rules/max-nested-describe.md +134 -0
- package/docs/rules/no-alias-methods.md +57 -0
- package/docs/rules/no-commented-out-tests.md +68 -0
- package/docs/rules/no-conditional-expect.md +142 -0
- package/docs/rules/no-conditional-in-test.md +123 -0
- package/docs/rules/no-confusing-set-timeout.md +64 -0
- package/docs/rules/no-deprecated-functions.md +59 -0
- package/docs/rules/no-disabled-tests.md +72 -0
- package/docs/rules/no-done-callback.md +100 -0
- package/docs/rules/no-duplicate-hooks.md +79 -0
- package/docs/rules/no-error-equal.md +37 -0
- package/docs/rules/no-export.md +52 -0
- package/docs/rules/no-focused-tests.md +67 -0
- package/docs/rules/no-hooks.md +178 -0
- package/docs/rules/no-identical-title.md +59 -0
- package/docs/rules/no-interpolation-in-snapshots.md +67 -0
- package/docs/rules/no-jasmine-globals.md +69 -0
- package/docs/rules/no-large-snapshots.md +180 -0
- package/docs/rules/no-mocks-import.md +34 -0
- package/docs/rules/no-restricted-jest-methods.md +53 -0
- package/docs/rules/no-restricted-matchers.md +64 -0
- package/docs/rules/no-standalone-expect.md +106 -0
- package/docs/rules/no-test-prefixes.md +42 -0
- package/docs/rules/no-test-return-statement.md +50 -0
- package/docs/rules/no-unnecessary-assertion.md +41 -0
- package/docs/rules/no-unneeded-async-expect-function.md +41 -0
- package/docs/rules/no-untyped-mock-factory.md +74 -0
- package/docs/rules/padding-around-after-all-blocks.md +34 -0
- package/docs/rules/padding-around-after-each-blocks.md +38 -0
- package/docs/rules/padding-around-all.md +20 -0
- package/docs/rules/padding-around-before-all-blocks.md +37 -0
- package/docs/rules/padding-around-before-each-blocks.md +38 -0
- package/docs/rules/padding-around-describe-blocks.md +42 -0
- package/docs/rules/padding-around-expect-groups.md +44 -0
- package/docs/rules/padding-around-test-blocks.md +48 -0
- package/docs/rules/prefer-called-with.md +39 -0
- package/docs/rules/prefer-comparison-matcher.md +62 -0
- package/docs/rules/prefer-each.md +58 -0
- package/docs/rules/prefer-ending-with-an-expect.md +170 -0
- package/docs/rules/prefer-equality-matcher.md +36 -0
- package/docs/rules/prefer-expect-assertions.md +230 -0
- package/docs/rules/prefer-expect-resolves.md +62 -0
- package/docs/rules/prefer-hooks-in-order.md +137 -0
- package/docs/rules/prefer-hooks-on-top.md +124 -0
- package/docs/rules/prefer-importing-jest-globals.md +85 -0
- package/docs/rules/prefer-jest-mocked.md +40 -0
- package/docs/rules/prefer-lowercase-title.md +128 -0
- package/docs/rules/prefer-mock-promise-shorthand.md +41 -0
- package/docs/rules/prefer-mock-return-shorthand.md +50 -0
- package/docs/rules/prefer-snapshot-hint.md +192 -0
- package/docs/rules/prefer-spy-on.md +46 -0
- package/docs/rules/prefer-strict-equal.md +29 -0
- package/docs/rules/prefer-to-be.md +63 -0
- package/docs/rules/prefer-to-contain.md +53 -0
- package/docs/rules/prefer-to-have-been-called-times.md +43 -0
- package/docs/rules/prefer-to-have-been-called.md +35 -0
- package/docs/rules/prefer-to-have-length.md +41 -0
- package/docs/rules/prefer-todo.md +33 -0
- package/docs/rules/require-hook.md +187 -0
- package/docs/rules/require-to-throw-message.md +43 -0
- package/docs/rules/require-top-level-describe.md +86 -0
- package/docs/rules/unbound-method.md +61 -0
- package/docs/rules/valid-describe-callback.md +69 -0
- package/docs/rules/valid-expect-in-promise.md +79 -0
- package/docs/rules/valid-expect-with-promise.md +43 -0
- package/docs/rules/valid-expect.md +155 -0
- package/docs/rules/valid-mock-module-path.md +72 -0
- package/docs/rules/valid-title.md +319 -0
- package/index.d.ts +28 -0
- package/lib/globals.json +15 -0
- package/lib/index.js +85 -0
- package/lib/rules/consistent-test-it.js +101 -0
- package/lib/rules/expect-expect.js +102 -0
- package/lib/rules/max-expects.js +70 -0
- package/lib/rules/max-nested-describe.js +59 -0
- package/lib/rules/no-alias-methods.js +62 -0
- package/lib/rules/no-commented-out-tests.js +44 -0
- package/lib/rules/no-conditional-expect.js +80 -0
- package/lib/rules/no-conditional-in-test.js +63 -0
- package/lib/rules/no-confusing-set-timeout.js +61 -0
- package/lib/rules/no-deprecated-functions.js +81 -0
- package/lib/rules/no-disabled-tests.js +57 -0
- package/lib/rules/no-done-callback.js +120 -0
- package/lib/rules/no-duplicate-hooks.js +52 -0
- package/lib/rules/no-error-equal.js +41 -0
- package/lib/rules/no-export.js +61 -0
- package/lib/rules/no-focused-tests.js +63 -0
- package/lib/rules/no-hooks.js +51 -0
- package/lib/rules/no-identical-title.js +73 -0
- package/lib/rules/no-interpolation-in-snapshots.js +43 -0
- package/lib/rules/no-jasmine-globals.js +140 -0
- package/lib/rules/no-large-snapshots.js +100 -0
- package/lib/rules/no-mocks-import.js +46 -0
- package/lib/rules/no-restricted-jest-methods.js +53 -0
- package/lib/rules/no-restricted-matchers.js +60 -0
- package/lib/rules/no-standalone-expect.js +114 -0
- package/lib/rules/no-test-prefixes.js +48 -0
- package/lib/rules/no-test-return-statement.js +62 -0
- package/lib/rules/no-unnecessary-assertion.js +87 -0
- package/lib/rules/no-unneeded-async-expect-function.js +57 -0
- package/lib/rules/no-untyped-mock-factory.js +61 -0
- package/lib/rules/padding-around-after-all-blocks.js +17 -0
- package/lib/rules/padding-around-after-each-blocks.js +17 -0
- package/lib/rules/padding-around-all.js +15 -0
- package/lib/rules/padding-around-before-all-blocks.js +17 -0
- package/lib/rules/padding-around-before-each-blocks.js +17 -0
- package/lib/rules/padding-around-describe-blocks.js +17 -0
- package/lib/rules/padding-around-expect-groups.js +21 -0
- package/lib/rules/padding-around-test-blocks.js +17 -0
- package/lib/rules/prefer-called-with.js +47 -0
- package/lib/rules/prefer-comparison-matcher.js +111 -0
- package/lib/rules/prefer-each.js +77 -0
- package/lib/rules/prefer-ending-with-an-expect.js +102 -0
- package/lib/rules/prefer-equality-matcher.js +87 -0
- package/lib/rules/prefer-expect-assertions.js +237 -0
- package/lib/rules/prefer-expect-resolves.js +47 -0
- package/lib/rules/prefer-hooks-in-order.js +67 -0
- package/lib/rules/prefer-hooks-on-top.js +41 -0
- package/lib/rules/prefer-importing-jest-globals.js +126 -0
- package/lib/rules/prefer-jest-mocked.js +66 -0
- package/lib/rules/prefer-lowercase-title.js +128 -0
- package/lib/rules/prefer-mock-promise-shorthand.js +88 -0
- package/lib/rules/prefer-mock-return-shorthand.js +122 -0
- package/lib/rules/prefer-snapshot-hint.js +111 -0
- package/lib/rules/prefer-spy-on.js +80 -0
- package/lib/rules/prefer-strict-equal.js +46 -0
- package/lib/rules/prefer-to-be.js +98 -0
- package/lib/rules/prefer-to-contain.js +82 -0
- package/lib/rules/prefer-to-have-been-called-times.js +70 -0
- package/lib/rules/prefer-to-have-been-called.js +59 -0
- package/lib/rules/prefer-to-have-length.js +57 -0
- package/lib/rules/prefer-todo.js +72 -0
- package/lib/rules/require-hook.js +93 -0
- package/lib/rules/require-to-throw-message.js +45 -0
- package/lib/rules/require-top-level-describe.js +86 -0
- package/lib/rules/unbound-method.js +86 -0
- package/lib/rules/utils/accessors.js +127 -0
- package/lib/rules/utils/ast-utils.js +59 -0
- package/lib/rules/utils/detectJestVersion.js +24 -0
- package/lib/rules/utils/followTypeAssertionChain.js +10 -0
- package/lib/rules/utils/index.js +71 -0
- package/lib/rules/utils/misc.js +168 -0
- package/lib/rules/utils/padding.js +308 -0
- package/lib/rules/utils/parseJestFnCall.js +325 -0
- package/lib/rules/utils/ts.js +73 -0
- package/lib/rules/valid-describe-callback.js +94 -0
- package/lib/rules/valid-expect-in-promise.js +311 -0
- package/lib/rules/valid-expect-with-promise.js +54 -0
- package/lib/rules/valid-expect.js +302 -0
- package/lib/rules/valid-mock-module-path.js +90 -0
- package/lib/rules/valid-title.js +252 -0
- package/package.json +164 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Jonathan Kim
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @depup/eslint-plugin-jest
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [eslint-plugin-jest](https://www.npmjs.com/package/eslint-plugin-jest)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/eslint-plugin-jest
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [eslint-plugin-jest](https://www.npmjs.com/package/eslint-plugin-jest) @ 29.15.1 |
|
|
17
|
+
| Processed | 2026-03-24 |
|
|
18
|
+
| Smoke test | passed |
|
|
19
|
+
| Deps updated | 1 |
|
|
20
|
+
|
|
21
|
+
## Dependency Changes
|
|
22
|
+
|
|
23
|
+
| Dependency | From | To |
|
|
24
|
+
|------------|------|-----|
|
|
25
|
+
| @typescript-eslint/utils | ^8.0.0 | ^8.57.2 |
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/eslint-plugin-jest
|
|
30
|
+
|
|
31
|
+
License inherited from the original package.
|
package/changes.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# jest/consistent-test-it
|
|
2
|
+
|
|
3
|
+
📝 Enforce `test` and `it` usage conventions.
|
|
4
|
+
|
|
5
|
+
🔧 This rule is automatically fixable by the
|
|
6
|
+
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
7
|
+
|
|
8
|
+
<!-- end auto-generated rule header -->
|
|
9
|
+
|
|
10
|
+
Jest allows you to choose how you want to define your tests, using the `it` or
|
|
11
|
+
the `test` keywords, with multiple permutations for each:
|
|
12
|
+
|
|
13
|
+
- **it:** `it`, `xit`, `fit`, `it.only`, `it.skip`.
|
|
14
|
+
- **test:** `test`, `xtest`, `test.only`, `test.skip`.
|
|
15
|
+
|
|
16
|
+
## Rule details
|
|
17
|
+
|
|
18
|
+
This rule gives you control over the usage of these keywords in your codebase.
|
|
19
|
+
|
|
20
|
+
## Options
|
|
21
|
+
|
|
22
|
+
This rule can be configured as follows
|
|
23
|
+
|
|
24
|
+
```json5
|
|
25
|
+
{
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
fn: {
|
|
29
|
+
enum: ['it', 'test'],
|
|
30
|
+
},
|
|
31
|
+
withinDescribe: {
|
|
32
|
+
enum: ['it', 'test'],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
additionalProperties: false,
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### fn
|
|
40
|
+
|
|
41
|
+
Decides whether to use `test` or `it`.
|
|
42
|
+
|
|
43
|
+
#### withinDescribe
|
|
44
|
+
|
|
45
|
+
Decides whether to use `test` or `it` within a `describe` scope.
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
/*eslint jest/consistent-test-it: ["error", {"fn": "test"}]*/
|
|
49
|
+
|
|
50
|
+
test('foo'); // valid
|
|
51
|
+
test.only('foo'); // valid
|
|
52
|
+
|
|
53
|
+
it('foo'); // invalid
|
|
54
|
+
it.only('foo'); // invalid
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
/*eslint jest/consistent-test-it: ["error", {"fn": "it"}]*/
|
|
59
|
+
|
|
60
|
+
it('foo'); // valid
|
|
61
|
+
it.only('foo'); // valid
|
|
62
|
+
|
|
63
|
+
test('foo'); // invalid
|
|
64
|
+
test.only('foo'); // invalid
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
/*eslint jest/consistent-test-it: ["error", {"fn": "it", "withinDescribe": "test"}]*/
|
|
69
|
+
|
|
70
|
+
it('foo'); // valid
|
|
71
|
+
describe('foo', function () {
|
|
72
|
+
test('bar'); // valid
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('foo'); // invalid
|
|
76
|
+
describe('foo', function () {
|
|
77
|
+
it('bar'); // invalid
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The default configuration forces all top-level tests to use `test` and all tests
|
|
82
|
+
nested within `describe` to use `it`.
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
/*eslint jest/consistent-test-it: ["error"]*/
|
|
86
|
+
|
|
87
|
+
test('foo'); // valid
|
|
88
|
+
describe('foo', function () {
|
|
89
|
+
it('bar'); // valid
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('foo'); // invalid
|
|
93
|
+
describe('foo', function () {
|
|
94
|
+
test('bar'); // invalid
|
|
95
|
+
});
|
|
96
|
+
```
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# jest/expect-expect
|
|
2
|
+
|
|
3
|
+
📝 Enforce assertion to be made in a test body.
|
|
4
|
+
|
|
5
|
+
⚠️ This rule _warns_ in the ✅ `recommended`
|
|
6
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
7
|
+
|
|
8
|
+
<!-- end auto-generated rule header -->
|
|
9
|
+
|
|
10
|
+
Ensure that there is at least one `expect` call made in a test.
|
|
11
|
+
|
|
12
|
+
## Rule details
|
|
13
|
+
|
|
14
|
+
This rule triggers when there is no call made to `expect` in a test, to prevent
|
|
15
|
+
users from forgetting to add assertions.
|
|
16
|
+
|
|
17
|
+
Examples of **incorrect** code for this rule:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
it('should be a test', () => {
|
|
21
|
+
console.log('no assertion');
|
|
22
|
+
});
|
|
23
|
+
test('should assert something', () => {});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Examples of **correct** code for this rule:
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
it('should be a test', () => {
|
|
30
|
+
expect(true).toBeDefined();
|
|
31
|
+
});
|
|
32
|
+
it('should work with callbacks/async', () => {
|
|
33
|
+
somePromise().then(res => expect(res).toBe('passed'));
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Options
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"jest/expect-expect": [
|
|
42
|
+
"error",
|
|
43
|
+
{
|
|
44
|
+
"assertFunctionNames": ["expect"],
|
|
45
|
+
"additionalTestBlockFunctions": []
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### `assertFunctionNames`
|
|
52
|
+
|
|
53
|
+
This array option specifies the names of functions that should be considered to
|
|
54
|
+
be asserting functions. Function names can use wildcards i.e `request.*.expect`,
|
|
55
|
+
`request.**.expect`, `request.*.expect*`
|
|
56
|
+
|
|
57
|
+
Examples of **incorrect** code for the `{ "assertFunctionNames": ["expect"] }`
|
|
58
|
+
option:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect"] }] */
|
|
62
|
+
|
|
63
|
+
import { expectSaga } from 'redux-saga-test-plan';
|
|
64
|
+
import { addSaga } from '../src/sagas';
|
|
65
|
+
|
|
66
|
+
test('returns sum', () => {
|
|
67
|
+
expectSaga(addSaga, 1, 1).returns(2).run();
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Examples of **correct** code for the
|
|
72
|
+
`{ "assertFunctionNames": ["expect", "expectSaga"] }` option:
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "expectSaga"] }] */
|
|
76
|
+
|
|
77
|
+
import { expectSaga } from 'redux-saga-test-plan';
|
|
78
|
+
import { addSaga } from '../src/sagas';
|
|
79
|
+
|
|
80
|
+
test('returns sum', () => {
|
|
81
|
+
expectSaga(addSaga, 1, 1).returns(2).run();
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Since the string is compiled into a regular expression, you'll need to escape
|
|
86
|
+
special characters such as `$` with a double backslash:
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect\\$"] }] */
|
|
90
|
+
|
|
91
|
+
it('is money-like', () => {
|
|
92
|
+
expect$(1.0);
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Examples of **correct** code for working with the HTTP assertions library
|
|
97
|
+
[SuperTest](https://www.npmjs.com/package/supertest) with the
|
|
98
|
+
`{ "assertFunctionNames": ["expect", "request.**.expect"] }` option:
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "request.**.expect"] }] */
|
|
102
|
+
const request = require('supertest');
|
|
103
|
+
const express = require('express');
|
|
104
|
+
|
|
105
|
+
const app = express();
|
|
106
|
+
|
|
107
|
+
describe('GET /user', function () {
|
|
108
|
+
it('responds with json', function (done) {
|
|
109
|
+
request(app).get('/user').expect('Content-Type', /json/).expect(200, done);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### `additionalTestBlockFunctions`
|
|
115
|
+
|
|
116
|
+
This array can be used to specify the names of functions that should also be
|
|
117
|
+
treated as test blocks:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"rules": {
|
|
122
|
+
"jest/expect-expect": [
|
|
123
|
+
"error",
|
|
124
|
+
{ "additionalTestBlockFunctions": ["theoretically"] }
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The following is _correct_ when using the above configuration:
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
import theoretically from 'jest-theories';
|
|
134
|
+
|
|
135
|
+
describe('NumberToLongString', () => {
|
|
136
|
+
const theories = [
|
|
137
|
+
{ input: 100, expected: 'One hundred' },
|
|
138
|
+
{ input: 1000, expected: 'One thousand' },
|
|
139
|
+
{ input: 10000, expected: 'Ten thousand' },
|
|
140
|
+
{ input: 100000, expected: 'One hundred thousand' },
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
theoretically(
|
|
144
|
+
'the number {input} is correctly translated to string',
|
|
145
|
+
theories,
|
|
146
|
+
theory => {
|
|
147
|
+
const output = NumberToLongString(theory.input);
|
|
148
|
+
expect(output).toBe(theory.expected);
|
|
149
|
+
},
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
```
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# jest/max-expects
|
|
2
|
+
|
|
3
|
+
📝 Enforces a maximum number assertion calls in a test body.
|
|
4
|
+
|
|
5
|
+
<!-- end auto-generated rule header -->
|
|
6
|
+
|
|
7
|
+
As more assertions are made, there is a possible tendency for the test to be
|
|
8
|
+
more likely to mix multiple objectives. To avoid this, this rule reports when
|
|
9
|
+
the maximum number of assertions is exceeded.
|
|
10
|
+
|
|
11
|
+
## Rule details
|
|
12
|
+
|
|
13
|
+
This rule enforces a maximum number of `expect()` calls.
|
|
14
|
+
|
|
15
|
+
The following patterns are considered warnings (with the default option of
|
|
16
|
+
`{ "max": 5 } `):
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
test('should not pass', () => {
|
|
20
|
+
expect(true).toBeDefined();
|
|
21
|
+
expect(true).toBeDefined();
|
|
22
|
+
expect(true).toBeDefined();
|
|
23
|
+
expect(true).toBeDefined();
|
|
24
|
+
expect(true).toBeDefined();
|
|
25
|
+
expect(true).toBeDefined();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should not pass', () => {
|
|
29
|
+
expect(true).toBeDefined();
|
|
30
|
+
expect(true).toBeDefined();
|
|
31
|
+
expect(true).toBeDefined();
|
|
32
|
+
expect(true).toBeDefined();
|
|
33
|
+
expect(true).toBeDefined();
|
|
34
|
+
expect(true).toBeDefined();
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The following patterns are **not** considered warnings (with the default option
|
|
39
|
+
of `{ "max": 5 } `):
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
test('shout pass');
|
|
43
|
+
|
|
44
|
+
test('shout pass', () => {});
|
|
45
|
+
|
|
46
|
+
test.skip('shout pass', () => {});
|
|
47
|
+
|
|
48
|
+
test('should pass', function () {
|
|
49
|
+
expect(true).toBeDefined();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('should pass', () => {
|
|
53
|
+
expect(true).toBeDefined();
|
|
54
|
+
expect(true).toBeDefined();
|
|
55
|
+
expect(true).toBeDefined();
|
|
56
|
+
expect(true).toBeDefined();
|
|
57
|
+
expect(true).toBeDefined();
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Options
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"jest/max-expects": [
|
|
66
|
+
"error",
|
|
67
|
+
{
|
|
68
|
+
"max": 5
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### `max`
|
|
75
|
+
|
|
76
|
+
Enforces a maximum number of `expect()`.
|
|
77
|
+
|
|
78
|
+
This has a default value of `5`.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# jest/max-nested-describe
|
|
2
|
+
|
|
3
|
+
📝 Enforces a maximum depth to nested describe calls.
|
|
4
|
+
|
|
5
|
+
<!-- end auto-generated rule header -->
|
|
6
|
+
|
|
7
|
+
While it's useful to be able to group your tests together within the same file
|
|
8
|
+
using `describe()`, having too many levels of nesting throughout your tests make
|
|
9
|
+
them difficult to read.
|
|
10
|
+
|
|
11
|
+
## Rule details
|
|
12
|
+
|
|
13
|
+
This rule enforces a maximum depth to nested `describe()` calls to improve code
|
|
14
|
+
clarity in your tests.
|
|
15
|
+
|
|
16
|
+
The following patterns are considered warnings (with the default option of
|
|
17
|
+
`{ "max": 5 } `):
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
describe('foo', () => {
|
|
21
|
+
describe('bar', () => {
|
|
22
|
+
describe('baz', () => {
|
|
23
|
+
describe('qux', () => {
|
|
24
|
+
describe('quxx', () => {
|
|
25
|
+
describe('too many', () => {
|
|
26
|
+
it('should get something', () => {
|
|
27
|
+
expect(getSomething()).toBe('Something');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('foo', function () {
|
|
37
|
+
describe('bar', function () {
|
|
38
|
+
describe('baz', function () {
|
|
39
|
+
describe('qux', function () {
|
|
40
|
+
describe('quxx', function () {
|
|
41
|
+
describe('too many', function () {
|
|
42
|
+
it('should get something', () => {
|
|
43
|
+
expect(getSomething()).toBe('Something');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The following patterns are **not** considered warnings (with the default option
|
|
54
|
+
of `{ "max": 5 } `):
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
describe('foo', () => {
|
|
58
|
+
describe('bar', () => {
|
|
59
|
+
it('should get something', () => {
|
|
60
|
+
expect(getSomething()).toBe('Something');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('qux', () => {
|
|
65
|
+
it('should get something', () => {
|
|
66
|
+
expect(getSomething()).toBe('Something');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('foo2', function () {
|
|
72
|
+
it('should get something', () => {
|
|
73
|
+
expect(getSomething()).toBe('Something');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('foo', function () {
|
|
78
|
+
describe('bar', function () {
|
|
79
|
+
describe('baz', function () {
|
|
80
|
+
describe('qux', function () {
|
|
81
|
+
describe('this is the limit', function () {
|
|
82
|
+
it('should get something', () => {
|
|
83
|
+
expect(getSomething()).toBe('Something');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Options
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"jest/max-nested-describe": [
|
|
97
|
+
"error",
|
|
98
|
+
{
|
|
99
|
+
"max": 5
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### `max`
|
|
106
|
+
|
|
107
|
+
Enforces a maximum depth for nested `describe()`.
|
|
108
|
+
|
|
109
|
+
This has a default value of `5`.
|
|
110
|
+
|
|
111
|
+
Examples of patterns **not** considered warnings with options set to
|
|
112
|
+
`{ "max": 2 }`:
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
describe('foo', () => {
|
|
116
|
+
describe('bar', () => {
|
|
117
|
+
it('should get something', () => {
|
|
118
|
+
expect(getSomething()).toBe('Something');
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('foo2', function () {
|
|
124
|
+
describe('bar2', function () {
|
|
125
|
+
it('should get something', function () {
|
|
126
|
+
expect(getSomething()).toBe('Something');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should get else', function () {
|
|
130
|
+
expect(getSomething()).toBe('Something');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
```
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# jest/no-alias-methods
|
|
2
|
+
|
|
3
|
+
📝 Disallow alias methods.
|
|
4
|
+
|
|
5
|
+
💼 This rule is enabled in the ✅ `recommended`
|
|
6
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
7
|
+
|
|
8
|
+
🔧 This rule is automatically fixable by the
|
|
9
|
+
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
10
|
+
|
|
11
|
+
<!-- end auto-generated rule header -->
|
|
12
|
+
|
|
13
|
+
> These aliases have been removed in Jest v30 - see
|
|
14
|
+
> <https://github.com/jestjs/jest/issues/13164> for more
|
|
15
|
+
|
|
16
|
+
Several Jest methods have alias names, such as `toThrow` having the alias of
|
|
17
|
+
`toThrowError`. This rule ensures that only the canonical name as used in the
|
|
18
|
+
Jest documentation is used in the code. This makes it easier to search for all
|
|
19
|
+
occurrences of the method within code, and it ensures consistency among the
|
|
20
|
+
method names used.
|
|
21
|
+
|
|
22
|
+
## Rule details
|
|
23
|
+
|
|
24
|
+
This rule triggers a warning if the alias name, rather than the canonical name,
|
|
25
|
+
of a method is used.
|
|
26
|
+
|
|
27
|
+
The following patterns are considered warnings:
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
expect(a).toBeCalled();
|
|
31
|
+
expect(a).toBeCalledTimes();
|
|
32
|
+
expect(a).toBeCalledWith();
|
|
33
|
+
expect(a).lastCalledWith();
|
|
34
|
+
expect(a).nthCalledWith();
|
|
35
|
+
expect(a).toReturn();
|
|
36
|
+
expect(a).toReturnTimes();
|
|
37
|
+
expect(a).toReturnWith();
|
|
38
|
+
expect(a).lastReturnedWith();
|
|
39
|
+
expect(a).nthReturnedWith();
|
|
40
|
+
expect(a).toThrowError();
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The following patterns are not considered warnings:
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
expect(a).toHaveBeenCalled();
|
|
47
|
+
expect(a).toHaveBeenCalledTimes();
|
|
48
|
+
expect(a).toHaveBeenCalledWith();
|
|
49
|
+
expect(a).toHaveBeenLastCalledWith();
|
|
50
|
+
expect(a).toHaveBeenNthCalledWith();
|
|
51
|
+
expect(a).toHaveReturned();
|
|
52
|
+
expect(a).toHaveReturnedTimes();
|
|
53
|
+
expect(a).toHaveReturnedWith();
|
|
54
|
+
expect(a).toHaveLastReturnedWith();
|
|
55
|
+
expect(a).toHaveNthReturnedWith();
|
|
56
|
+
expect(a).toThrow();
|
|
57
|
+
```
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# jest/no-commented-out-tests
|
|
2
|
+
|
|
3
|
+
📝 Disallow commented out tests.
|
|
4
|
+
|
|
5
|
+
⚠️ This rule _warns_ in the ✅ `recommended`
|
|
6
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
7
|
+
|
|
8
|
+
<!-- end auto-generated rule header -->
|
|
9
|
+
|
|
10
|
+
This rule raises a warning about commented out tests. It's similar to
|
|
11
|
+
no-disabled-tests rule.
|
|
12
|
+
|
|
13
|
+
## Rule details
|
|
14
|
+
|
|
15
|
+
The rule uses fuzzy matching to do its best to determine what constitutes a
|
|
16
|
+
commented out test, checking for a presence of `it(`, `describe(`, `it.skip(`,
|
|
17
|
+
etc. in code comments.
|
|
18
|
+
|
|
19
|
+
The following patterns are considered warnings:
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// describe('foo', () => {});
|
|
23
|
+
// it('foo', () => {});
|
|
24
|
+
// test('foo', () => {});
|
|
25
|
+
|
|
26
|
+
// describe.skip('foo', () => {});
|
|
27
|
+
// it.skip('foo', () => {});
|
|
28
|
+
// test.skip('foo', () => {});
|
|
29
|
+
|
|
30
|
+
// describe['skip']('bar', () => {});
|
|
31
|
+
// it['skip']('bar', () => {});
|
|
32
|
+
// test['skip']('bar', () => {});
|
|
33
|
+
|
|
34
|
+
// xdescribe('foo', () => {});
|
|
35
|
+
// xit('foo', () => {});
|
|
36
|
+
// xtest('foo', () => {});
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
describe('foo', () => {});
|
|
40
|
+
*/
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
These patterns would not be considered warnings:
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
describe('foo', () => {});
|
|
47
|
+
it('foo', () => {});
|
|
48
|
+
test('foo', () => {});
|
|
49
|
+
|
|
50
|
+
describe.only('bar', () => {});
|
|
51
|
+
it.only('bar', () => {});
|
|
52
|
+
test.only('bar', () => {});
|
|
53
|
+
|
|
54
|
+
// foo('bar', () => {});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Limitations
|
|
58
|
+
|
|
59
|
+
The plugin looks at the literal function names within test code, so will not
|
|
60
|
+
catch more complex examples of commented out tests, such as:
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
// const testSkip = test.skip;
|
|
64
|
+
// testSkip('skipped test', () => {});
|
|
65
|
+
|
|
66
|
+
// const myTest = test;
|
|
67
|
+
// myTest('does not have function body');
|
|
68
|
+
```
|