Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prefer-to-be): preserve resolves and rejects modifiers #980

Merged
merged 1 commit into from Nov 8, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/rules/__tests__/prefer-to-be.test.ts
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
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