eslint-plugin-jest 24.3.1 → 24.3.5

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,32 @@
1
+ ## [24.3.5](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.4...v24.3.5) (2021-04-10)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **valid-describe:** support using `each` with modifiers ([#820](https://github.com/jest-community/eslint-plugin-jest/issues/820)) ([cbdbcef](https://github.com/jest-community/eslint-plugin-jest/commit/cbdbcef47984eb01509493bd5b2423f518a2663d))
7
+
8
+ ## [24.3.4](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.3...v24.3.4) (2021-04-05)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * support all variations of `describe`, `it`, & `test` ([#792](https://github.com/jest-community/eslint-plugin-jest/issues/792)) ([0968b55](https://github.com/jest-community/eslint-plugin-jest/commit/0968b557dd9cdb5cfcaf8a0d84e8a456825e6b25))
14
+
15
+ ## [24.3.3](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.2...v24.3.3) (2021-04-02)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **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)
21
+ * **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)
22
+
23
+ ## [24.3.2](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.1...v24.3.2) (2021-03-16)
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * **consistent-test-it:** properly handle `describe.each` ([#796](https://github.com/jest-community/eslint-plugin-jest/issues/796)) ([035bd30](https://github.com/jest-community/eslint-plugin-jest/commit/035bd30af43f1215e65bf1b26c2ef2e6d174d3c8)), closes [#795](https://github.com/jest-community/eslint-plugin-jest/issues/795)
29
+
1
30
  ## [24.3.1](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.0...v24.3.1) (2021-03-13)
2
31
 
3
32
 
@@ -12,7 +12,7 @@ whenever you are using the exclusivity feature.
12
12
  ## Rule Details
13
13
 
14
14
  This rule looks for every `describe.only`, `it.only`, `test.only`, `fdescribe`,
15
- `fit` and `ftest` occurrences within the source code. Of course there are some
15
+ and `fit` occurrences within the source code. Of course there are some
16
16
  edge-cases which can’t be detected by this rule e.g.:
17
17
 
18
18
  ```js
@@ -31,13 +31,9 @@ test.only('foo', () => {});
31
31
  test['only']('bar', () => {});
32
32
  fdescribe('foo', () => {});
33
33
  fit('foo', () => {});
34
- ftest('bar', () => {});
35
34
  fit.each`
36
35
  table
37
36
  `();
38
- ftest.each`
39
- table
40
- `();
41
37
  ```
42
38
 
43
39
  These patterns would not be considered warnings:
@@ -56,13 +56,13 @@ var _default = (0, _utils.createRule)({
56
56
  return;
57
57
  }
58
58
 
59
- if ((0, _utils.isDescribe)(node)) {
59
+ if ((0, _utils.isDescribeCall)(node)) {
60
60
  describeNestingLevel++;
61
61
  }
62
62
 
63
63
  const funcNode = node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee;
64
64
 
65
- if ((0, _utils.isTestCase)(node) && describeNestingLevel === 0 && !nodeName.includes(testKeyword)) {
65
+ if ((0, _utils.isTestCaseCall)(node) && describeNestingLevel === 0 && !nodeName.includes(testKeyword)) {
66
66
  const oppositeTestKeyword = getOppositeTestKeyword(testKeyword);
67
67
  context.report({
68
68
  messageId: 'consistentMethod',
@@ -75,7 +75,7 @@ var _default = (0, _utils.createRule)({
75
75
  });
76
76
  }
77
77
 
78
- if ((0, _utils.isTestCase)(node) && describeNestingLevel > 0 && !nodeName.includes(testKeywordWithinDescribe)) {
78
+ if ((0, _utils.isTestCaseCall)(node) && describeNestingLevel > 0 && !nodeName.includes(testKeywordWithinDescribe)) {
79
79
  const oppositeTestKeyword = getOppositeTestKeyword(testKeywordWithinDescribe);
80
80
  context.report({
81
81
  messageId: 'consistentMethodWithinDescribe',
@@ -90,7 +90,7 @@ var _default = (0, _utils.createRule)({
90
90
  },
91
91
 
92
92
  'CallExpression:exit'(node) {
93
- if ((0, _utils.isDescribe)(node)) {
93
+ if ((0, _utils.isDescribeCall)(node) && !(0, _utils.isEachCall)(node)) {
94
94
  describeNestingLevel--;
95
95
  }
96
96
  }
@@ -12,14 +12,12 @@ var _utils = require("./utils");
12
12
  const hasStringAsFirstArgument = node => node.arguments[0] && (0, _utils.isStringNode)(node.arguments[0]);
13
13
 
14
14
  const findNodeNameAndArgument = node => {
15
- if (!((0, _utils.isTestCase)(node) || (0, _utils.isDescribe)(node))) {
15
+ if (!((0, _utils.isTestCaseCall)(node) || (0, _utils.isDescribeCall)(node))) {
16
16
  return null;
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
 
@@ -85,7 +83,7 @@ var _default = (0, _utils.createRule)({
85
83
  let numberOfDescribeBlocks = 0;
86
84
  return {
87
85
  CallExpression(node) {
88
- if ((0, _utils.isDescribe)(node)) {
86
+ if ((0, _utils.isDescribeCall)(node)) {
89
87
  numberOfDescribeBlocks++;
90
88
 
91
89
  if (ignoreTopLevelDescribe && numberOfDescribeBlocks === 1) {
@@ -130,7 +128,7 @@ var _default = (0, _utils.createRule)({
130
128
  },
131
129
 
132
130
  'CallExpression:exit'(node) {
133
- if ((0, _utils.isDescribe)(node)) {
131
+ if ((0, _utils.isDescribeCall)(node)) {
134
132
  numberOfDescribeBlocks--;
135
133
  }
136
134
  }
@@ -42,7 +42,7 @@ var _default = (0, _utils.createRule)({
42
42
  },
43
43
 
44
44
  CallExpression(node) {
45
- if ((0, _utils.isTestCase)(node)) {
45
+ if ((0, _utils.isTestCaseCall)(node)) {
46
46
  inTestCase = true;
47
47
  }
48
48
 
@@ -55,7 +55,7 @@ var _default = (0, _utils.createRule)({
55
55
  },
56
56
 
57
57
  'CallExpression:exit'(node) {
58
- if ((0, _utils.isTestCase)(node)) {
58
+ if ((0, _utils.isTestCaseCall)(node)) {
59
59
  inTestCase = false;
60
60
  }
61
61
  },
@@ -18,7 +18,7 @@ const findCallbackArg = (node, isJestEach) => {
18
18
  return node.arguments[0];
19
19
  }
20
20
 
21
- if ((0, _utils.isTestCase)(node) && node.arguments.length >= 2) {
21
+ if ((0, _utils.isTestCaseCall)(node) && node.arguments.length >= 2) {
22
22
  return node.arguments[1];
23
23
  }
24
24
 
@@ -34,7 +34,7 @@ var _default = (0, _utils.createRule)({
34
34
  const hookContexts = [newHookContext()];
35
35
  return {
36
36
  CallExpression(node) {
37
- if ((0, _utils.isDescribe)(node)) {
37
+ if ((0, _utils.isDescribeCall)(node)) {
38
38
  hookContexts.push(newHookContext());
39
39
  }
40
40
 
@@ -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.isDescribeCall)(node) && !(0, _utils.isEachCall)(node)) {
59
59
  hookContexts.pop();
60
60
  }
61
61
  }
@@ -41,7 +41,7 @@ var _default = (0, _utils.createRule)({
41
41
  },
42
42
 
43
43
  CallExpression(node) {
44
- if ((0, _utils.isTestCase)(node)) {
44
+ if ((0, _utils.isTestCaseCall)(node)) {
45
45
  hasTestCase = true;
46
46
  }
47
47
  },
@@ -37,7 +37,7 @@ var _default = (0, _utils.createRule)({
37
37
  CallExpression(node) {
38
38
  const currentLayer = contexts[contexts.length - 1];
39
39
 
40
- if ((0, _utils.isDescribe)(node)) {
40
+ if ((0, _utils.isDescribeCall)(node)) {
41
41
  contexts.push(newDescribeContext());
42
42
  }
43
43
 
@@ -53,7 +53,7 @@ var _default = (0, _utils.createRule)({
53
53
 
54
54
  const title = (0, _utils.getStringValue)(argument);
55
55
 
56
- if ((0, _utils.isTestCase)(node)) {
56
+ if ((0, _utils.isTestCaseCall)(node)) {
57
57
  if (currentLayer.testTitles.includes(title)) {
58
58
  context.report({
59
59
  messageId: 'multipleTestTitle',
@@ -64,7 +64,7 @@ var _default = (0, _utils.createRule)({
64
64
  currentLayer.testTitles.push(title);
65
65
  }
66
66
 
67
- if (!(0, _utils.isDescribe)(node)) {
67
+ if (!(0, _utils.isDescribeCall)(node)) {
68
68
  return;
69
69
  }
70
70
 
@@ -79,7 +79,7 @@ var _default = (0, _utils.createRule)({
79
79
  },
80
80
 
81
81
  'CallExpression:exit'(node) {
82
- if ((0, _utils.isDescribe)(node)) {
82
+ if ((0, _utils.isDescribeCall)(node)) {
83
83
  contexts.pop();
84
84
  }
85
85
  }
@@ -56,7 +56,7 @@ var _default = (0, _utils.createRule)({
56
56
 
57
57
  return {
58
58
  CallExpression(node) {
59
- if ((0, _utils.isTestCase)(node)) {
59
+ if ((0, _utils.isTestCaseCall)(node)) {
60
60
  stack.push(true);
61
61
  }
62
62
  },
@@ -30,7 +30,7 @@ const getBlockType = statement => {
30
30
  } // if it's not a variable, it will be callExpr, we only care about describe
31
31
 
32
32
 
33
- if (expr.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && (0, _utils.isDescribe)(expr)) {
33
+ if (expr.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && (0, _utils.isDescribeCall)(expr)) {
34
34
  return 'describe';
35
35
  }
36
36
  }
@@ -75,7 +75,7 @@ var _default = (0, _utils.createRule)({
75
75
 
76
76
  const isCustomTestBlockFunction = node => additionalTestBlockFunctions.includes((0, _utils.getNodeName)(node) || '');
77
77
 
78
- const isTestBlock = node => (0, _utils.isTestCase)(node) || isCustomTestBlockFunction(node);
78
+ const isTestBlock = node => (0, _utils.isTestCaseCall)(node) || isCustomTestBlockFunction(node);
79
79
 
80
80
  return {
81
81
  CallExpression(node) {
@@ -30,7 +30,7 @@ var _default = (0, _utils.createRule)({
30
30
  return {
31
31
  CallExpression(node) {
32
32
  const nodeName = (0, _utils.getNodeName)(node.callee);
33
- if (!nodeName || !(0, _utils.isDescribe)(node) && !(0, _utils.isTestCase)(node)) return;
33
+ if (!nodeName || !(0, _utils.isDescribeCall)(node) && !(0, _utils.isTestCaseCall)(node)) return;
34
34
  const preferredNodeName = getPreferredNodeName(nodeName);
35
35
  if (!preferredNodeName) return;
36
36
  const funcNode = node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee;
@@ -38,7 +38,7 @@ var _default = (0, _utils.createRule)({
38
38
  create(context) {
39
39
  return {
40
40
  CallExpression(node) {
41
- if (!(0, _utils.isTestCase)(node)) return;
41
+ if (!(0, _utils.isTestCaseCall)(node)) return;
42
42
  const body = getBody(node.arguments);
43
43
  const returnStmt = body.find(t => t.type === _experimentalUtils.AST_NODE_TYPES.ReturnStatement);
44
44
  if (!returnStmt) return;
@@ -35,7 +35,7 @@ var _default = (0, _utils.createRule)({
35
35
 
36
36
  return {
37
37
  CallExpression(node) {
38
- if ((0, _utils.isTestCase)(node)) {
38
+ if ((0, _utils.isTestCaseCall)(node)) {
39
39
  isTest = true;
40
40
  } else if (isTest && isThrowExpectCall(node)) {
41
41
  context.report({
@@ -67,7 +67,7 @@ var _default = (0, _utils.createRule)({
67
67
  },
68
68
 
69
69
  'CallExpression:exit'(node) {
70
- if ((0, _utils.isTestCase)(node)) {
70
+ if ((0, _utils.isTestCaseCall)(node)) {
71
71
  isTest = false;
72
72
  }
73
73
  },
@@ -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.isTestCaseCall)(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;
@@ -27,7 +27,7 @@ var _default = (0, _utils.createRule)({
27
27
  const hooksContext = [false];
28
28
  return {
29
29
  CallExpression(node) {
30
- if (!(0, _utils.isHook)(node) && (0, _utils.isTestCase)(node)) {
30
+ if (!(0, _utils.isHook)(node) && (0, _utils.isTestCaseCall)(node)) {
31
31
  hooksContext[hooksContext.length - 1] = true;
32
32
  }
33
33
 
@@ -22,7 +22,7 @@ function createTodoFixer(node, fixer) {
22
22
  return fixer.replaceText(node.callee, `${testName}.todo`);
23
23
  }
24
24
 
25
- const isTargetedTestCase = node => (0, _utils.isTestCase)(node) && [_utils.TestCaseName.it, _utils.TestCaseName.test, 'it.skip', 'test.skip'].includes((0, _utils.getNodeName)(node.callee));
25
+ const isTargetedTestCase = node => (0, _utils.isTestCaseCall)(node) && [_utils.TestCaseName.it, _utils.TestCaseName.test, 'it.skip', 'test.skip'].includes((0, _utils.getNodeName)(node.callee));
26
26
 
27
27
  var _default = (0, _utils.createRule)({
28
28
  name: __filename,
@@ -28,13 +28,13 @@ var _default = (0, _utils.createRule)({
28
28
  let numberOfDescribeBlocks = 0;
29
29
  return {
30
30
  CallExpression(node) {
31
- if ((0, _utils.isDescribe)(node)) {
31
+ if ((0, _utils.isDescribeCall)(node)) {
32
32
  numberOfDescribeBlocks++;
33
33
  return;
34
34
  }
35
35
 
36
36
  if (numberOfDescribeBlocks === 0) {
37
- if ((0, _utils.isTestCase)(node)) {
37
+ if ((0, _utils.isTestCaseCall)(node)) {
38
38
  context.report({
39
39
  node,
40
40
  messageId: 'unexpectedTestCase'
@@ -53,7 +53,7 @@ var _default = (0, _utils.createRule)({
53
53
  },
54
54
 
55
55
  'CallExpression:exit'(node) {
56
- if ((0, _utils.isDescribe)(node) && !(0, _utils.isEachCall)(node)) {
56
+ if ((0, _utils.isDescribeCall)(node) && !(0, _utils.isEachCall)(node)) {
57
57
  numberOfDescribeBlocks--;
58
58
  }
59
59
  }
@@ -50,6 +50,8 @@ const tryCreateBaseRule = context => {
50
50
  }
51
51
  };
52
52
 
53
+ const DEFAULT_MESSAGE = 'This rule requires `@typescript-eslint/eslint-plugin`';
54
+
53
55
  var _default = (0, _utils.createRule)({
54
56
  defaultOptions: [{
55
57
  ignoreStatic: false
@@ -58,7 +60,8 @@ var _default = (0, _utils.createRule)({
58
60
  name: __filename,
59
61
  meta: {
60
62
  messages: {
61
- unbound: 'This rule requires `@typescript-eslint/eslint-plugin`'
63
+ unbound: DEFAULT_MESSAGE,
64
+ unboundWithoutThisAnnotation: DEFAULT_MESSAGE
62
65
  },
63
66
  schema: [],
64
67
  type: 'problem',
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getNodeName = getNodeName;
7
- exports.scopeHasLocalReference = exports.getJestFunctionArguments = exports.isEachCall = exports.isDescribe = exports.isTestCase = exports.getTestCallExpressionsFromDeclaredVariables = exports.isHook = exports.isFunction = exports.TestCaseProperty = exports.DescribeProperty = exports.HookName = exports.TestCaseName = exports.DescribeAlias = exports.parseExpectCall = exports.isParsedEqualityMatcherCall = exports.EqualityMatcher = exports.ModifierName = exports.isExpectMember = exports.isExpectCall = exports.getAccessorValue = exports.isSupportedAccessor = exports.hasOnlyOneArgument = exports.getStringValue = exports.isStringNode = exports.followTypeAssertionChain = exports.createRule = void 0;
7
+ exports.scopeHasLocalReference = exports.getJestFunctionArguments = exports.isEachCall = exports.isDescribeCall = exports.isTestCaseCall = exports.getTestCallExpressionsFromDeclaredVariables = exports.isHook = exports.isFunction = exports.TestCaseProperty = exports.DescribeProperty = exports.HookName = exports.TestCaseName = exports.DescribeAlias = exports.parseExpectCall = exports.isParsedEqualityMatcherCall = exports.EqualityMatcher = exports.ModifierName = exports.isExpectMember = exports.isExpectCall = exports.getAccessorValue = exports.isSupportedAccessor = exports.hasOnlyOneArgument = exports.getStringValue = exports.isStringNode = exports.followTypeAssertionChain = exports.createRule = void 0;
8
8
 
9
9
  var _path = require("path");
10
10
 
@@ -390,31 +390,103 @@ const getTestCallExpressionsFromDeclaredVariables = declaredVariables => {
390
390
  references
391
391
  }) => acc.concat(references.map(({
392
392
  identifier
393
- }) => identifier.parent).filter(node => !!node && node.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && isTestCase(node))), []);
393
+ }) => identifier.parent).filter(node => !!node && node.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && isTestCaseCall(node))), []);
394
394
  };
395
395
 
396
396
  exports.getTestCallExpressionsFromDeclaredVariables = getTestCallExpressionsFromDeclaredVariables;
397
397
 
398
- const isTestCase = node => node.callee.type === _experimentalUtils.AST_NODE_TYPES.Identifier && TestCaseName.hasOwnProperty(node.callee.name) || // e.g. it.each``()
399
- 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 && TestCaseName.hasOwnProperty(node.callee.tag.object.name) && isSupportedAccessor(node.callee.tag.property, TestCaseProperty.each) || // e.g. it.concurrent.{skip,only}
400
- node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && node.callee.property.type === _experimentalUtils.AST_NODE_TYPES.Identifier && TestCaseProperty.hasOwnProperty(node.callee.property.name) && (node.callee.object.type === _experimentalUtils.AST_NODE_TYPES.Identifier && TestCaseName.hasOwnProperty(node.callee.object.name) || node.callee.object.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && node.callee.object.object.type === _experimentalUtils.AST_NODE_TYPES.Identifier && TestCaseName.hasOwnProperty(node.callee.object.object.name));
398
+ const isTestCaseName = node => node.type === _experimentalUtils.AST_NODE_TYPES.Identifier && TestCaseName.hasOwnProperty(node.name);
401
399
 
402
- exports.isTestCase = isTestCase;
400
+ const isTestCaseProperty = node => isSupportedAccessor(node) && TestCaseProperty.hasOwnProperty(getAccessorValue(node));
401
+ /**
402
+ * Checks if the given `node` is a *call* to a test case function that would
403
+ * result in tests being run by `jest`.
404
+ *
405
+ * Note that `.each()` does not count as a call in this context, as it will not
406
+ * result in `jest` running any tests.
407
+ *
408
+ * @param {TSESTree.CallExpression} node
409
+ *
410
+ * @return {node is JestFunctionCallExpression<TestCaseName>}
411
+ */
412
+
413
+
414
+ const isTestCaseCall = node => {
415
+ if (isTestCaseName(node.callee)) {
416
+ return true;
417
+ }
418
+
419
+ const callee = node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee;
420
+
421
+ if (callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isTestCaseProperty(callee.property)) {
422
+ var _node$parent;
423
+
424
+ // if we're an `each()`, ensure we're being called (i.e `.each()()`)
425
+ if (node.callee.type !== _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression && ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) !== _experimentalUtils.AST_NODE_TYPES.CallExpression && getAccessorValue(callee.property) === 'each') {
426
+ return false;
427
+ }
428
+
429
+ return callee.object.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression ? isTestCaseName(callee.object.object) : isTestCaseName(callee.object);
430
+ }
431
+
432
+ return false;
433
+ };
434
+
435
+ exports.isTestCaseCall = isTestCaseCall;
436
+
437
+ const isDescribeAlias = node => node.type === _experimentalUtils.AST_NODE_TYPES.Identifier && DescribeAlias.hasOwnProperty(node.name);
403
438
 
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);
439
+ const isDescribeProperty = node => isSupportedAccessor(node) && DescribeProperty.hasOwnProperty(getAccessorValue(node));
405
440
  /**
406
- * Checks if the given node` is a call to `<describe|test|it>.each(...)`.
407
- * If `true`, the code must look like `<method>.each(...)`.
441
+ * Checks if the given `node` is a *call* to a `describe` function that would
442
+ * result in a `describe` block being created by `jest`.
443
+ *
444
+ * Note that `.each()` does not count as a call in this context, as it will not
445
+ * result in `jest` creating any `describe` blocks.
446
+ *
447
+ * @param {TSESTree.CallExpression} node
448
+ *
449
+ * @return {node is JestFunctionCallExpression<TestCaseName>}
450
+ */
451
+
452
+
453
+ const isDescribeCall = node => {
454
+ if (isDescribeAlias(node.callee)) {
455
+ return true;
456
+ }
457
+
458
+ const callee = node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee;
459
+
460
+ if (callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isDescribeProperty(callee.property)) {
461
+ var _node$parent2;
462
+
463
+ // if we're an `each()`, ensure we're being called (i.e `.each()()`)
464
+ if (node.callee.type !== _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression && ((_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.type) !== _experimentalUtils.AST_NODE_TYPES.CallExpression && getAccessorValue(callee.property) === 'each') {
465
+ return false;
466
+ }
467
+
468
+ return callee.object.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression ? isDescribeAlias(callee.object.object) : isDescribeAlias(callee.object);
469
+ }
470
+
471
+ return false;
472
+ };
473
+ /**
474
+ * Checks if the given node` is a call to `<describe|test|it>.each(...)()`.
475
+ * If `true`, the code must look like `<method>.each(...)()`.
408
476
  *
409
477
  * @param {JestFunctionCallExpression<DescribeAlias | TestCaseName>} node
410
478
  *
411
- * @return {node is JestFunctionCallExpressionWithMemberExpressionCallee<DescribeAlias | TestCaseName, DescribeProperty.each | TestCaseProperty.each>}
479
+ * @return {node is JestFunctionCallExpressionWithMemberExpressionCallee<DescribeAlias | TestCaseName, DescribeProperty.each | TestCaseProperty.each> & {parent: TSESTree.CallExpression}}
412
480
  */
413
481
 
414
482
 
415
- exports.isDescribe = isDescribe;
483
+ exports.isDescribeCall = isDescribeCall;
416
484
 
417
- const isEachCall = node => node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.property, DescribeProperty.each);
485
+ const isEachCall = node => {
486
+ var _node$parent3;
487
+
488
+ return ((_node$parent3 = node.parent) === null || _node$parent3 === void 0 ? void 0 : _node$parent3.type) === _experimentalUtils.AST_NODE_TYPES.CallExpression && node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.property, DescribeProperty.each);
489
+ };
418
490
  /**
419
491
  * Gets the arguments of the given `JestFunctionCallExpression`.
420
492
  *
@@ -41,7 +41,7 @@ var _default = (0, _utils.createRule)({
41
41
  create(context) {
42
42
  return {
43
43
  CallExpression(node) {
44
- if (!(0, _utils.isDescribe)(node) || node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression) {
44
+ if (!(0, _utils.isDescribeCall)(node) || node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression) {
45
45
  return;
46
46
  }
47
47
 
@@ -132,7 +132,7 @@ var _default = (0, _utils.createRule)({
132
132
  const mustMatchPatterns = compileMatcherPatterns(mustMatch !== null && mustMatch !== void 0 ? mustMatch : {});
133
133
  return {
134
134
  CallExpression(node) {
135
- if (!(0, _utils.isDescribe)(node) && !(0, _utils.isTestCase)(node)) {
135
+ if (!(0, _utils.isDescribeCall)(node) && !(0, _utils.isTestCaseCall)(node)) {
136
136
  return;
137
137
  }
138
138
 
@@ -147,7 +147,7 @@ var _default = (0, _utils.createRule)({
147
147
  return;
148
148
  }
149
149
 
150
- if (argument.type !== _experimentalUtils.AST_NODE_TYPES.TemplateLiteral && !(ignoreTypeOfDescribeName && (0, _utils.isDescribe)(node))) {
150
+ if (argument.type !== _experimentalUtils.AST_NODE_TYPES.TemplateLiteral && !(ignoreTypeOfDescribeName && (0, _utils.isDescribeCall)(node))) {
151
151
  context.report({
152
152
  messageId: 'titleMustBeString',
153
153
  loc: argument.loc
@@ -163,7 +163,7 @@ var _default = (0, _utils.createRule)({
163
163
  context.report({
164
164
  messageId: 'emptyTitle',
165
165
  data: {
166
- jestFunctionName: (0, _utils.isDescribe)(node) ? _utils.DescribeAlias.describe : _utils.TestCaseName.test
166
+ jestFunctionName: (0, _utils.isDescribeCall)(node) ? _utils.DescribeAlias.describe : _utils.TestCaseName.test
167
167
  },
168
168
  node
169
169
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "24.3.1",
3
+ "version": "24.3.5",
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",