eslint-plugin-jest 25.1.0 → 25.2.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 CHANGED
@@ -1,3 +1,10 @@
1
+ # [25.2.0](https://github.com/jest-community/eslint-plugin-jest/compare/v25.1.0...v25.2.0) (2021-10-14)
2
+
3
+
4
+ ### Features
5
+
6
+ * **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))
7
+
1
8
  # [25.1.0](https://github.com/jest-community/eslint-plugin-jest/compare/v25.0.6...v25.1.0) (2021-10-14)
2
9
 
3
10
 
@@ -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
+ ```
@@ -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,13 @@ 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 : '';
85
95
 
86
- if (name === _utils.TestCaseName.it || name === _utils.TestCaseName.test) {
96
+ if ((0, _utils.isTestCaseCall)(node) || additionalTestBlockFunctions.includes(name)) {
87
97
  unchecked.push(node);
88
- } else if (name && matchesAssertFunctionName(name, assertFunctionNames)) {
98
+ } else if (matchesAssertFunctionName(name, assertFunctionNames)) {
89
99
  // Return early in case of nested `it` statements.
90
100
  checkCallExpressionUsed(context.getAncestors());
91
101
  }
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.0",
4
4
  "description": "Eslint rules for Jest",
5
5
  "keywords": [
6
6
  "eslint",