Skip to content

Commit

Permalink
fix(prefer-to-be): preserve resolves and rejects modifiers (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored Nov 8, 2021
1 parent 43e1722 commit a1296bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/rules/__tests__/prefer-to-be.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ ruleTester.run('prefer-to-be: undefined', rule, {
output: 'expect("a string").toBeDefined();',
errors: [{ messageId: 'useToBeDefined', column: 24, line: 1 }],
},
{
code: 'expect("a string").rejects.not.toBe(undefined);',
output: 'expect("a string").rejects.toBeDefined();',
errors: [{ messageId: 'useToBeDefined', column: 32, line: 1 }],
},
{
code: 'expect("a string").not.toEqual(undefined);',
output: 'expect("a string").toBeDefined();',
Expand Down Expand Up @@ -181,6 +186,11 @@ ruleTester.run('prefer-to-be: NaN', rule, {
output: 'expect("a string").not.toBeNaN();',
errors: [{ messageId: 'useToBeNaN', column: 24, line: 1 }],
},
{
code: 'expect("a string").rejects.not.toBe(NaN);',
output: 'expect("a string").rejects.not.toBeNaN();',
errors: [{ messageId: 'useToBeNaN', column: 32, line: 1 }],
},
{
code: 'expect("a string").not.toEqual(NaN);',
output: 'expect("a string").not.toBeNaN();',
Expand Down Expand Up @@ -218,6 +228,11 @@ ruleTester.run('prefer-to-be: undefined vs defined', rule, {
output: 'expect(undefined).resolves.toBeUndefined();',
errors: [{ messageId: 'useToBeUndefined', column: 32, line: 1 }],
},
{
code: 'expect(undefined).resolves.toBe(undefined);',
output: 'expect(undefined).resolves.toBeUndefined();',
errors: [{ messageId: 'useToBeUndefined', column: 28, line: 1 }],
},
{
code: 'expect("a string").not.toBeUndefined();',
output: 'expect("a string").toBeDefined();',
Expand Down
4 changes: 3 additions & 1 deletion src/rules/prefer-to-be.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ const reportPreferToBe = (
matcher: ParsedExpectMatcher,
modifier?: ParsedExpectModifier,
) => {
const modifierNode = modifier?.negation || modifier?.node;
const modifierNode =
modifier?.negation ||
(modifier?.name === ModifierName.not && modifier?.node);

context.report({
messageId: `useToBe${whatToBe}`,
Expand Down

0 comments on commit a1296bd

Please sign in to comment.