diff --git a/src/rules/__tests__/prefer-to-be.test.ts b/src/rules/__tests__/prefer-to-be.test.ts index 2cf92e69b..bd9630d84 100644 --- a/src/rules/__tests__/prefer-to-be.test.ts +++ b/src/rules/__tests__/prefer-to-be.test.ts @@ -14,6 +14,8 @@ ruleTester.run('prefer-to-be', rule, { 'expect(value).toMatchSnapshot();', "expect(catchError()).toStrictEqual({ message: 'oh noes!' })", 'expect("something");', + 'expect(token).toStrictEqual(/[abc]+/g);', + "expect(token).toStrictEqual(new RegExp('[abc]+', 'g'));", ], invalid: [ { diff --git a/src/rules/prefer-to-be.ts b/src/rules/prefer-to-be.ts index 687d774b8..a67fdb54b 100644 --- a/src/rules/prefer-to-be.ts +++ b/src/rules/prefer-to-be.ts @@ -35,8 +35,11 @@ const isFirstArgumentIdentifier = ( name: string, ) => isIdentifier(getFirstArgument(matcher), name); -const isPrimitiveLiteral = (matcher: ParsedEqualityMatcherCall) => - getFirstArgument(matcher).type === AST_NODE_TYPES.Literal; +const isPrimitiveLiteral = (matcher: ParsedEqualityMatcherCall): boolean => { + const firstArg = getFirstArgument(matcher); + + return firstArg.type === AST_NODE_TYPES.Literal && !('regex' in firstArg); +}; const getFirstArgument = (matcher: ParsedEqualityMatcherCall) => { return followTypeAssertionChain(matcher.arguments[0]);