eslint-plugin-jest 22.1.1 → 22.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "22.1.1",
3
+ "version": "22.1.2",
4
4
  "description": "Eslint rules for Jest",
5
5
  "repository": "jest-community/eslint-plugin-jest",
6
6
  "license": "MIT",
@@ -153,5 +153,41 @@ ruleTester.run('no-alias-methods', rule, {
153
153
  ],
154
154
  output: 'expect(a).toThrow()',
155
155
  },
156
+ {
157
+ code: 'expect(a).resolves.toThrowError()',
158
+ errors: [
159
+ {
160
+ message:
161
+ 'Replace toThrowError() with its canonical name of toThrow()',
162
+ column: 20,
163
+ line: 1,
164
+ },
165
+ ],
166
+ output: 'expect(a).resolves.toThrow()',
167
+ },
168
+ {
169
+ code: 'expect(a).rejects.toThrowError()',
170
+ errors: [
171
+ {
172
+ message:
173
+ 'Replace toThrowError() with its canonical name of toThrow()',
174
+ column: 19,
175
+ line: 1,
176
+ },
177
+ ],
178
+ output: 'expect(a).rejects.toThrow()',
179
+ },
180
+ {
181
+ code: 'expect(a).not.toThrowError()',
182
+ errors: [
183
+ {
184
+ message:
185
+ 'Replace toThrowError() with its canonical name of toThrow()',
186
+ column: 15,
187
+ line: 1,
188
+ },
189
+ ],
190
+ output: 'expect(a).not.toThrow()',
191
+ },
156
192
  ],
157
193
  });
@@ -32,9 +32,19 @@ module.exports = {
32
32
  return;
33
33
  }
34
34
 
35
- // Check if the method used matches any of ours.
36
- const propertyName = method(node) && method(node).name;
37
- const methodItem = methodNames.find(item => item[1] === propertyName);
35
+ let targetNode = method(node);
36
+ if (
37
+ targetNode.name === 'resolves' ||
38
+ targetNode.name === 'rejects' ||
39
+ targetNode.name === 'not'
40
+ ) {
41
+ targetNode = method(node.parent);
42
+ }
43
+
44
+ // Check if the method used matches any of ours
45
+ const methodItem = methodNames.find(
46
+ item => item[1] === targetNode.name
47
+ );
38
48
 
39
49
  if (methodItem) {
40
50
  context.report({
@@ -43,9 +53,9 @@ module.exports = {
43
53
  replace: methodItem[1],
44
54
  canonical: methodItem[0],
45
55
  },
46
- node: method(node),
56
+ node: targetNode,
47
57
  fix(fixer) {
48
- return [fixer.replaceText(method(node), methodItem[0])];
58
+ return [fixer.replaceText(targetNode, methodItem[0])];
49
59
  },
50
60
  });
51
61
  }