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

prefer-to-be considers RegExp literal notation as a literal #921

Closed
amikheychik opened this issue Oct 4, 2021 · 3 comments · Fixed by #922
Closed

prefer-to-be considers RegExp literal notation as a literal #921

amikheychik opened this issue Oct 4, 2021 · 3 comments · Fixed by #922

Comments

@amikheychik
Copy link

amikheychik commented Oct 4, 2021

The literal notation of a regular expression in JavaScript is still a RegExp object. But The prefer-to-be rule treats literal notation as a literal. So it auto-fixes .toStrictEqual into .toBe, causing tests to fail.

For example, given two tests that pass:

it('is an example', () => {
  const token: RegExp = new RegExp('[abc]+', 'gu');

  expect(token).toStrictEqual(/[abc]+/gu);
  expect(token).toStrictEqual(new RegExp('[abc]+', 'gu'));
});

Is changed into:

it('is an example', () => {
  const token: RegExp = new RegExp('[abc]+', 'gu');

  expect(token).toBe(/[abc]+/gu);
  expect(token).toStrictEqual(new RegExp('[abc]+', 'gu'));
});

And the .toBe test fails

@G-Rath
Copy link
Collaborator

G-Rath commented Oct 4, 2021

Ah good catch! thanks

@github-actions
Copy link

github-actions bot commented Oct 4, 2021

🎉 This issue has been resolved in version 24.5.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This issue has been resolved in version 25.0.0-next.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants