eslint-plugin-jest 24.3.2 → 24.3.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,11 @@
1
+ ## [24.3.3](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.2...v24.3.3) (2021-04-02)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **no-duplicate-hooks:** support `describe.each` ([#797](https://github.com/jest-community/eslint-plugin-jest/issues/797)) ([243cb4f](https://github.com/jest-community/eslint-plugin-jest/commit/243cb4f970e40aa195a3bffa0528dbdbfef7c4f5)), closes [#642](https://github.com/jest-community/eslint-plugin-jest/issues/642)
7
+ * **prefer-expect-assertions:** support `.each` ([#798](https://github.com/jest-community/eslint-plugin-jest/issues/798)) ([f758243](https://github.com/jest-community/eslint-plugin-jest/commit/f75824359f2242f53997c59c238d83a59badeea3)), closes [#676](https://github.com/jest-community/eslint-plugin-jest/issues/676)
8
+
1
9
  ## [24.3.2](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.1...v24.3.2) (2021-03-16)
2
10
 
3
11
 
@@ -17,9 +17,7 @@ const findNodeNameAndArgument = node => {
17
17
  }
18
18
 
19
19
  if ((0, _utils.isEachCall)(node)) {
20
- var _node$parent;
21
-
22
- if (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) === _experimentalUtils.AST_NODE_TYPES.CallExpression && hasStringAsFirstArgument(node.parent)) {
20
+ if (node.parent.arguments.length > 0 && (0, _utils.isStringNode)(node.parent.arguments[0])) {
23
21
  return [node.callee.object.name, node.parent.arguments[0]];
24
22
  }
25
23
 
@@ -55,7 +55,7 @@ var _default = (0, _utils.createRule)({
55
55
  },
56
56
 
57
57
  'CallExpression:exit'(node) {
58
- if ((0, _utils.isDescribe)(node)) {
58
+ if ((0, _utils.isDescribe)(node) && !(0, _utils.isEachCall)(node)) {
59
59
  hookContexts.pop();
60
60
  }
61
61
  }
@@ -55,12 +55,24 @@ var _default = (0, _utils.createRule)({
55
55
 
56
56
  create(context, [options]) {
57
57
  return {
58
- 'CallExpression[callee.name=/^(it|test)$/][arguments.1.body.body]'(node) {
59
- if (options.onlyFunctionsWithAsyncKeyword && !node.arguments[1].async) {
58
+ CallExpression(node) {
59
+ if (!(0, _utils.isTestCase)(node)) {
60
60
  return;
61
61
  }
62
62
 
63
- const testFuncBody = node.arguments[1].body.body;
63
+ const args = (0, _utils.isEachCall)(node) ? node.parent.arguments : node.arguments;
64
+
65
+ if (args.length < 2) {
66
+ return;
67
+ }
68
+
69
+ const [, testFn] = args;
70
+
71
+ if (!(0, _utils.isFunction)(testFn) || testFn.body.type !== _experimentalUtils.AST_NODE_TYPES.BlockStatement || options.onlyFunctionsWithAsyncKeyword && !testFn.async) {
72
+ return;
73
+ }
74
+
75
+ const testFuncBody = testFn.body.body;
64
76
 
65
77
  if (!isFirstLineExprStmt(testFuncBody)) {
66
78
  context.report({
@@ -68,7 +80,7 @@ var _default = (0, _utils.createRule)({
68
80
  node,
69
81
  suggest: suggestions.map(([messageId, text]) => ({
70
82
  messageId,
71
- fix: fixer => fixer.insertTextBeforeRange([node.arguments[1].body.range[0] + 1, node.arguments[1].body.range[1]], text)
83
+ fix: fixer => fixer.insertTextBeforeRange([testFn.body.range[0] + 1, testFn.body.range[1]], text)
72
84
  }))
73
85
  });
74
86
  return;
@@ -403,18 +403,22 @@ exports.isTestCase = isTestCase;
403
403
 
404
404
  const isDescribe = node => node.callee.type === _experimentalUtils.AST_NODE_TYPES.Identifier && DescribeAlias.hasOwnProperty(node.callee.name) || node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && node.callee.object.type === _experimentalUtils.AST_NODE_TYPES.Identifier && DescribeAlias.hasOwnProperty(node.callee.object.name) && node.callee.property.type === _experimentalUtils.AST_NODE_TYPES.Identifier && DescribeProperty.hasOwnProperty(node.callee.property.name) || node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression && node.callee.tag.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && node.callee.tag.object.type === _experimentalUtils.AST_NODE_TYPES.Identifier && DescribeAlias.hasOwnProperty(node.callee.tag.object.name);
405
405
  /**
406
- * Checks if the given node` is a call to `<describe|test|it>.each(...)`.
407
- * If `true`, the code must look like `<method>.each(...)`.
406
+ * Checks if the given node` is a call to `<describe|test|it>.each(...)()`.
407
+ * If `true`, the code must look like `<method>.each(...)()`.
408
408
  *
409
409
  * @param {JestFunctionCallExpression<DescribeAlias | TestCaseName>} node
410
410
  *
411
- * @return {node is JestFunctionCallExpressionWithMemberExpressionCallee<DescribeAlias | TestCaseName, DescribeProperty.each | TestCaseProperty.each>}
411
+ * @return {node is JestFunctionCallExpressionWithMemberExpressionCallee<DescribeAlias | TestCaseName, DescribeProperty.each | TestCaseProperty.each> & {parent: TSESTree.CallExpression}}
412
412
  */
413
413
 
414
414
 
415
415
  exports.isDescribe = isDescribe;
416
416
 
417
- const isEachCall = node => node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.property, DescribeProperty.each);
417
+ const isEachCall = node => {
418
+ var _node$parent;
419
+
420
+ return ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) === _experimentalUtils.AST_NODE_TYPES.CallExpression && node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.property, DescribeProperty.each);
421
+ };
418
422
  /**
419
423
  * Gets the arguments of the given `JestFunctionCallExpression`.
420
424
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "24.3.2",
3
+ "version": "24.3.3",
4
4
  "description": "Eslint rules for Jest",
5
5
  "keywords": [
6
6
  "eslint",
@@ -108,7 +108,7 @@
108
108
  "eslint-plugin-import": "^2.20.2",
109
109
  "eslint-plugin-node": "^11.0.0",
110
110
  "eslint-plugin-prettier": "^3.0.0",
111
- "husky": "^5.1.3",
111
+ "husky": "^6.0.0",
112
112
  "is-ci": "^3.0.0",
113
113
  "jest": "^26.0.1",
114
114
  "jest-runner-eslint": "^0.10.0",