Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions rules/__tests__/no-alias-methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,41 @@ ruleTester.run('no-alias-methods', rule, {
],
output: 'expect(a).toThrow()',
},
{
code: 'expect(a).resolves.toThrowError()',
errors: [
{
message:
'Replace toThrowError() with its canonical name of toThrow()',
column: 20,
line: 1,
},
],
output: 'expect(a).resolves.toThrow()',
},
{
code: 'expect(a).rejects.toThrowError()',
errors: [
{
message:
'Replace toThrowError() with its canonical name of toThrow()',
column: 19,
line: 1,
},
],
output: 'expect(a).rejects.toThrow()',
},
{
code: 'expect(a).not.toThrowError()',
errors: [
{
message:
'Replace toThrowError() with its canonical name of toThrow()',
column: 15,
line: 1,
},
],
output: 'expect(a).not.toThrow()',
},
],
});
20 changes: 15 additions & 5 deletions rules/no-alias-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,19 @@ module.exports = {
return;
}

// Check if the method used matches any of ours.
const propertyName = method(node) && method(node).name;
const methodItem = methodNames.find(item => item[1] === propertyName);
let targetNode = method(node);
if (
targetNode.name === 'resolves' ||
targetNode.name === 'rejects' ||
targetNode.name === 'not'
) {
targetNode = method(node.parent);
}

// Check if the method used matches any of ours
const methodItem = methodNames.find(
item => item[1] === targetNode.name
);

if (methodItem) {
context.report({
Expand All @@ -43,9 +53,9 @@ module.exports = {
replace: methodItem[1],
canonical: methodItem[0],
},
node: method(node),
node: targetNode,
fix(fixer) {
return [fixer.replaceText(method(node), methodItem[0])];
return [fixer.replaceText(targetNode, methodItem[0])];
},
});
}
Expand Down