eslint-plugin-jest 25.1.0 → 25.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ ## [25.2.3](https://github.com/jest-community/eslint-plugin-jest/compare/v25.2.2...v25.2.3) (2021-11-04)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **no-deprecated-functions:** mark jest as an optional peer dependency ([#970](https://github.com/jest-community/eslint-plugin-jest/issues/970)) ([f468752](https://github.com/jest-community/eslint-plugin-jest/commit/f468752fc0aba89dd9bcce5fe676a04cb2fa6407))
7
+
8
+ ## [25.2.2](https://github.com/jest-community/eslint-plugin-jest/compare/v25.2.1...v25.2.2) (2021-10-17)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **require-hook:** check variables are either `const` or declarations ([#959](https://github.com/jest-community/eslint-plugin-jest/issues/959)) ([ce8cd61](https://github.com/jest-community/eslint-plugin-jest/commit/ce8cd612b7c4c16dc29934118b191d3fbe1ffc07))
14
+
15
+ ## [25.2.1](https://github.com/jest-community/eslint-plugin-jest/compare/v25.2.0...v25.2.1) (2021-10-15)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **expect-expect:** don't error on `it.todo` & `test.todo` calls ([#954](https://github.com/jest-community/eslint-plugin-jest/issues/954)) ([d3cc0db](https://github.com/jest-community/eslint-plugin-jest/commit/d3cc0db129f8d2021cf278f656b73b8c7efb2dc2))
21
+
22
+ # [25.2.0](https://github.com/jest-community/eslint-plugin-jest/compare/v25.1.0...v25.2.0) (2021-10-14)
23
+
24
+
25
+ ### Features
26
+
27
+ * **expect-expect:** support `additionalTestBlockFunctions` option ([#850](https://github.com/jest-community/eslint-plugin-jest/issues/850)) ([3b94c62](https://github.com/jest-community/eslint-plugin-jest/commit/3b94c62b81a50bc8b213c597bb59799cff1ef207))
28
+
1
29
  # [25.1.0](https://github.com/jest-community/eslint-plugin-jest/compare/v25.0.6...v25.1.0) (2021-10-14)
2
30
 
3
31
 
@@ -34,7 +34,8 @@ it('should work with callbacks/async', () => {
34
34
  "jest/expect-expect": [
35
35
  "error",
36
36
  {
37
- "assertFunctionNames": ["expect"]
37
+ "assertFunctionNames": ["expect"],
38
+ "additionalTestBlockFunctions": []
38
39
  }
39
40
  ]
40
41
  }
@@ -102,3 +103,43 @@ describe('GET /user', function () {
102
103
  });
103
104
  });
104
105
  ```
106
+
107
+ ### `additionalTestBlockFunctions`
108
+
109
+ This array can be used to specify the names of functions that should also be
110
+ treated as test blocks:
111
+
112
+ ```json
113
+ {
114
+ "rules": {
115
+ "jest/expect-expect": [
116
+ "error",
117
+ { "additionalTestBlockFunctions": ["theoretically"] }
118
+ ]
119
+ }
120
+ }
121
+ ```
122
+
123
+ The following is _correct_ when using the above configuration:
124
+
125
+ ```js
126
+ import theoretically from 'jest-theories';
127
+
128
+ describe('NumberToLongString', () => {
129
+ const theories = [
130
+ { input: 100, expected: 'One hundred' },
131
+ { input: 1000, expected: 'One thousand' },
132
+ { input: 10000, expected: 'Ten thousand' },
133
+ { input: 100000, expected: 'One hundred thousand' },
134
+ ];
135
+
136
+ theoretically(
137
+ 'the number {input} is correctly translated to string',
138
+ theories,
139
+ theory => {
140
+ const output = NumberToLongString(theory.input);
141
+ expect(output).toBe(theory.expected);
142
+ },
143
+ );
144
+ });
145
+ ```
@@ -26,7 +26,7 @@ it('adds 1 + 2 to equal 3', () => {
26
26
 
27
27
  ```json
28
28
  {
29
- "jest/prefer-lowercase-name": [
29
+ "jest/prefer-lowercase-title": [
30
30
  "error",
31
31
  {
32
32
  "ignore": ["describe", "test"]
@@ -50,7 +50,7 @@ By default, none of these options are enabled (the equivalent of
50
50
  Example of **correct** code for the `{ "ignore": ["describe"] }` option:
51
51
 
52
52
  ```js
53
- /* eslint jest/prefer-lowercase-name: ["error", { "ignore": ["describe"] }] */
53
+ /* eslint jest/prefer-lowercase-title: ["error", { "ignore": ["describe"] }] */
54
54
 
55
55
  describe('Uppercase description');
56
56
  ```
@@ -58,7 +58,7 @@ describe('Uppercase description');
58
58
  Example of **correct** code for the `{ "ignore": ["test"] }` option:
59
59
 
60
60
  ```js
61
- /* eslint jest/prefer-lowercase-name: ["error", { "ignore": ["test"] }] */
61
+ /* eslint jest/prefer-lowercase-title: ["error", { "ignore": ["test"] }] */
62
62
 
63
63
  test('Uppercase description');
64
64
  ```
@@ -66,7 +66,7 @@ test('Uppercase description');
66
66
  Example of **correct** code for the `{ "ignore": ["it"] }` option:
67
67
 
68
68
  ```js
69
- /* eslint jest/prefer-lowercase-name: ["error", { "ignore": ["it"] }] */
69
+ /* eslint jest/prefer-lowercase-title: ["error", { "ignore": ["it"] }] */
70
70
 
71
71
  it('Uppercase description');
72
72
  ```
@@ -82,7 +82,7 @@ By default, nothing is allowed (the equivalent of `{ "allowedPrefixes": [] }`).
82
82
  Example of **correct** code for the `{ "allowedPrefixes": ["GET"] }` option:
83
83
 
84
84
  ```js
85
- /* eslint jest/prefer-lowercase-name: ["error", { "allowedPrefixes": ["GET"] }] */
85
+ /* eslint jest/prefer-lowercase-title: ["error", { "allowedPrefixes": ["GET"] }] */
86
86
 
87
87
  describe('GET /live');
88
88
  ```
@@ -95,7 +95,7 @@ title starting with an upper-case letter.
95
95
  Example of **correct** code for the `{ "ignoreTopLevelDescribe": true }` option:
96
96
 
97
97
  ```js
98
- /* eslint jest/prefer-lowercase-name: ["error", { "ignoreTopLevelDescribe": true }] */
98
+ /* eslint jest/prefer-lowercase-title: ["error", { "ignoreTopLevelDescribe": true }] */
99
99
  describe('MyClass', () => {
100
100
  describe('#myMethod', () => {
101
101
  it('does things', () => {
@@ -19,7 +19,8 @@ directly within the body of a `describe`, _except_ for the following:
19
19
 
20
20
  - `import` statements
21
21
  - `const` variables
22
- - `let` _declarations_
22
+ - `let` _declarations_, and initializations to `null` or `undefined`
23
+ - Classes
23
24
  - Types
24
25
  - Calls to the standard Jest globals
25
26
 
@@ -47,6 +47,12 @@ var _default = (0, _utils.createRule)({
47
47
  items: [{
48
48
  type: 'string'
49
49
  }]
50
+ },
51
+ additionalTestBlockFunctions: {
52
+ type: 'array',
53
+ items: {
54
+ type: 'string'
55
+ }
50
56
  }
51
57
  },
52
58
  additionalProperties: false
@@ -54,11 +60,13 @@ var _default = (0, _utils.createRule)({
54
60
  type: 'suggestion'
55
61
  },
56
62
  defaultOptions: [{
57
- assertFunctionNames: ['expect']
63
+ assertFunctionNames: ['expect'],
64
+ additionalTestBlockFunctions: []
58
65
  }],
59
66
 
60
67
  create(context, [{
61
- assertFunctionNames = ['expect']
68
+ assertFunctionNames = ['expect'],
69
+ additionalTestBlockFunctions = []
62
70
  }]) {
63
71
  const unchecked = [];
64
72
 
@@ -81,11 +89,17 @@ var _default = (0, _utils.createRule)({
81
89
 
82
90
  return {
83
91
  CallExpression(node) {
84
- const name = (0, _utils.getNodeName)(node.callee);
92
+ var _getNodeName;
93
+
94
+ const name = (_getNodeName = (0, _utils.getNodeName)(node.callee)) !== null && _getNodeName !== void 0 ? _getNodeName : '';
95
+
96
+ if ((0, _utils.isTestCaseCall)(node) || additionalTestBlockFunctions.includes(name)) {
97
+ if (node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && (0, _utils.isSupportedAccessor)(node.callee.property, 'todo')) {
98
+ return;
99
+ }
85
100
 
86
- if (name === _utils.TestCaseName.it || name === _utils.TestCaseName.test) {
87
101
  unchecked.push(node);
88
- } else if (name && matchesAssertFunctionName(name, assertFunctionNames)) {
102
+ } else if (matchesAssertFunctionName(name, assertFunctionNames)) {
89
103
  // Return early in case of nested `it` statements.
90
104
  checkCallExpressionUsed(context.getAncestors());
91
105
  }
@@ -19,6 +19,10 @@ const isJestFnCall = node => {
19
19
  return !!((_getNodeName = (0, _utils.getNodeName)(node)) !== null && _getNodeName !== void 0 && _getNodeName.startsWith('jest.'));
20
20
  };
21
21
 
22
+ const isNullOrUndefined = node => {
23
+ return node.type === _experimentalUtils.AST_NODE_TYPES.Literal && node.value === null || (0, _utils.isIdentifier)(node, 'undefined');
24
+ };
25
+
22
26
  const shouldBeInHook = node => {
23
27
  switch (node.type) {
24
28
  case _experimentalUtils.AST_NODE_TYPES.ExpressionStatement:
@@ -27,6 +31,17 @@ const shouldBeInHook = node => {
27
31
  case _experimentalUtils.AST_NODE_TYPES.CallExpression:
28
32
  return !isJestFnCall(node);
29
33
 
34
+ case _experimentalUtils.AST_NODE_TYPES.VariableDeclaration:
35
+ {
36
+ if (node.kind === 'const') {
37
+ return false;
38
+ }
39
+
40
+ return node.declarations.some(({
41
+ init
42
+ }) => init !== null && !isNullOrUndefined(init));
43
+ }
44
+
30
45
  default:
31
46
  return false;
32
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "25.1.0",
3
+ "version": "25.2.3",
4
4
  "description": "Eslint rules for Jest",
5
5
  "keywords": [
6
6
  "eslint",
@@ -96,7 +96,7 @@
96
96
  "@semantic-release/git": "^10.0.0",
97
97
  "@types/dedent": "^0.7.0",
98
98
  "@types/jest": "^27.0.0",
99
- "@types/node": "^14.0.0",
99
+ "@types/node": "^16.0.0",
100
100
  "@types/prettier": "^2.0.0",
101
101
  "@typescript-eslint/eslint-plugin": "^5.0.0",
102
102
  "@typescript-eslint/parser": "^5.0.0",
@@ -107,7 +107,7 @@
107
107
  "eslint-config-prettier": "^8.3.0",
108
108
  "eslint-plugin-eslint-comments": "^3.1.2",
109
109
  "eslint-plugin-eslint-config": "^2.0.0",
110
- "eslint-plugin-eslint-plugin": "^3.5.3",
110
+ "eslint-plugin-eslint-plugin": "^4.0.1",
111
111
  "eslint-plugin-import": "^2.25.1",
112
112
  "eslint-plugin-node": "^11.0.0",
113
113
  "eslint-plugin-prettier": "^3.4.1",
@@ -131,6 +131,9 @@
131
131
  "peerDependenciesMeta": {
132
132
  "@typescript-eslint/eslint-plugin": {
133
133
  "optional": true
134
+ },
135
+ "jest": {
136
+ "optional": true
134
137
  }
135
138
  },
136
139
  "engines": {
@@ -155,5 +158,6 @@
155
158
  },
156
159
  "resolutions": {
157
160
  "@typescript-eslint/experimental-utils": "^5.0.0"
158
- }
161
+ },
162
+ "packageManager": "yarn@3.0.2"
159
163
  }