Skip to content

Commit 99b6d42

Browse files
authored
fix(prefer-to-be): don't consider RegExp literals as toBe-able (#922)
1 parent 546e837 commit 99b6d42

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/rules/__tests__/prefer-to-be.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ ruleTester.run('prefer-to-be', rule, {
1414
'expect(value).toMatchSnapshot();',
1515
"expect(catchError()).toStrictEqual({ message: 'oh noes!' })",
1616
'expect("something");',
17+
'expect(token).toStrictEqual(/[abc]+/g);',
18+
"expect(token).toStrictEqual(new RegExp('[abc]+', 'g'));",
1719
],
1820
invalid: [
1921
{

src/rules/prefer-to-be.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ const isFirstArgumentIdentifier = (
3535
name: string,
3636
) => isIdentifier(getFirstArgument(matcher), name);
3737

38-
const isPrimitiveLiteral = (matcher: ParsedEqualityMatcherCall) =>
39-
getFirstArgument(matcher).type === AST_NODE_TYPES.Literal;
38+
const isPrimitiveLiteral = (matcher: ParsedEqualityMatcherCall): boolean => {
39+
const firstArg = getFirstArgument(matcher);
40+
41+
return firstArg.type === AST_NODE_TYPES.Literal && !('regex' in firstArg);
42+
};
4043

4144
const getFirstArgument = (matcher: ParsedEqualityMatcherCall) => {
4245
return followTypeAssertionChain(matcher.arguments[0]);

0 commit comments

Comments
 (0)