diff --git a/src/rules/__tests__/prefer-to-be.test.ts b/src/rules/__tests__/prefer-to-be.test.ts index bd9630d84..3b9a6ac0a 100644 --- a/src/rules/__tests__/prefer-to-be.test.ts +++ b/src/rules/__tests__/prefer-to-be.test.ts @@ -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();', @@ -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();', @@ -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();', diff --git a/src/rules/prefer-to-be.ts b/src/rules/prefer-to-be.ts index a67fdb54b..165a129d7 100644 --- a/src/rules/prefer-to-be.ts +++ b/src/rules/prefer-to-be.ts @@ -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}`,