eslint-plugin-jest 26.5.0 → 26.5.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.
@@ -33,19 +33,20 @@ var _default = (0, _utils.createRule)({
33
33
  const {
34
34
  modifier,
35
35
  matcher
36
- } = (0, _utils.parseExpectCall)(node); // Could check resolves/rejects here but not a likely idiom.
37
-
38
- if (matcher && !modifier) {
39
- if (['toBeCalled', 'toHaveBeenCalled'].includes(matcher.name)) {
40
- context.report({
41
- data: {
42
- name: matcher.name
43
- },
44
- // todo: rename to 'matcherName'
45
- messageId: 'preferCalledWith',
46
- node: matcher.node.property
47
- });
48
- }
36
+ } = (0, _utils.parseExpectCall)(node);
37
+
38
+ if (!matcher || (modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils.ModifierName.not || modifier !== null && modifier !== void 0 && modifier.negation) {
39
+ return;
40
+ }
41
+
42
+ if (['toBeCalled', 'toHaveBeenCalled'].includes(matcher.name)) {
43
+ context.report({
44
+ data: {
45
+ name: matcher.name
46
+ },
47
+ messageId: 'preferCalledWith',
48
+ node: matcher.node.property
49
+ });
49
50
  }
50
51
  }
51
52
 
@@ -108,7 +108,10 @@ var _default = (0, _utils2.createRule)({
108
108
  return;
109
109
  }
110
110
 
111
- const preferredMatcher = determineMatcher(comparison.operator, (0, _utils2.followTypeAssertionChain)(matcher.arguments[0]).value === !!modifier);
111
+ const negation = modifier !== null && modifier !== void 0 && modifier.negation ? {
112
+ node: modifier.negation
113
+ } : (modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils2.ModifierName.not ? modifier : null;
114
+ const preferredMatcher = determineMatcher(comparison.operator, (0, _utils2.followTypeAssertionChain)(matcher.arguments[0]).value === !!negation);
112
115
 
113
116
  if (!preferredMatcher) {
114
117
  return;
@@ -116,10 +119,12 @@ var _default = (0, _utils2.createRule)({
116
119
 
117
120
  context.report({
118
121
  fix(fixer) {
119
- const sourceCode = context.getSourceCode();
122
+ const sourceCode = context.getSourceCode(); // preserve the existing modifier if it's not a negation
123
+
124
+ const modifierText = modifier && (modifier === null || modifier === void 0 ? void 0 : modifier.node) !== (negation === null || negation === void 0 ? void 0 : negation.node) ? `.${modifier.name}` : '';
120
125
  return [// replace the comparison argument with the left-hand side of the comparison
121
126
  fixer.replaceText(comparison, sourceCode.getText(comparison.left)), // replace the current matcher & modifier with the preferred matcher
122
- fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], `.${preferredMatcher}`), // replace the matcher argument with the right-hand side of the comparison
127
+ fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], `${modifierText}.${preferredMatcher}`), // replace the matcher argument with the right-hand side of the comparison
123
128
  fixer.replaceText(matcher.arguments[0], sourceCode.getText(comparison.right))];
124
129
  },
125
130
 
@@ -127,7 +132,7 @@ var _default = (0, _utils2.createRule)({
127
132
  data: {
128
133
  preferredMatcher
129
134
  },
130
- node: (modifier || matcher).node.property
135
+ node: (negation || matcher).node.property
131
136
  });
132
137
  }
133
138
 
@@ -64,16 +64,26 @@ var _default = (0, _utils2.createRule)({
64
64
  return;
65
65
  }
66
66
 
67
- const matcherValue = (0, _utils2.followTypeAssertionChain)(matcher.arguments[0]).value; // we need to negate the expectation if the current expected
67
+ const matcherValue = (0, _utils2.followTypeAssertionChain)(matcher.arguments[0]).value;
68
+ const negation = modifier !== null && modifier !== void 0 && modifier.negation ? {
69
+ node: modifier.negation
70
+ } : (modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils2.ModifierName.not ? modifier : null; // we need to negate the expectation if the current expected
68
71
  // value is itself negated by the "not" modifier
69
72
 
70
- const addNotModifier = (comparison.operator === '!==' ? !matcherValue : matcherValue) === !!modifier;
73
+ const addNotModifier = (comparison.operator === '!==' ? !matcherValue : matcherValue) === !!negation;
71
74
 
72
75
  const buildFixer = equalityMatcher => fixer => {
73
- const sourceCode = context.getSourceCode();
76
+ const sourceCode = context.getSourceCode(); // preserve the existing modifier if it's not a negation
77
+
78
+ let modifierText = modifier && (modifier === null || modifier === void 0 ? void 0 : modifier.node) !== (negation === null || negation === void 0 ? void 0 : negation.node) ? `.${modifier.name}` : '';
79
+
80
+ if (addNotModifier) {
81
+ modifierText += `.${_utils2.ModifierName.not}`;
82
+ }
83
+
74
84
  return [// replace the comparison argument with the left-hand side of the comparison
75
85
  fixer.replaceText(comparison, sourceCode.getText(comparison.left)), // replace the current matcher & modifier with the preferred matcher
76
- fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], addNotModifier ? `.${_utils2.ModifierName.not}.${equalityMatcher}` : `.${equalityMatcher}`), // replace the matcher argument with the right-hand side of the comparison
86
+ fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], `${modifierText}.${equalityMatcher}`), // replace the matcher argument with the right-hand side of the comparison
77
87
  fixer.replaceText(matcher.arguments[0], sourceCode.getText(comparison.right))];
78
88
  };
79
89
 
@@ -86,7 +96,7 @@ var _default = (0, _utils2.createRule)({
86
96
  },
87
97
  fix: buildFixer(equalityMatcher)
88
98
  })),
89
- node: (modifier || matcher).node.property
99
+ node: (negation || matcher).node.property
90
100
  });
91
101
  }
92
102
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "26.5.0",
3
+ "version": "26.5.3",
4
4
  "description": "ESLint rules for Jest",
5
5
  "keywords": [
6
6
  "eslint",