jest icon indicating copy to clipboard operation
jest copied to clipboard

toMatchObject passes with non-matching RegExp objects

Open jarruda opened this issue 3 years ago • 3 comments

🐛 Bug Report

When using toMatchObject with a RegExp object as a value, the test passes with any RegExp object. It behaves as though the matching object used expect.any(RegExp) instead of an instance.

To Reproduce

test('toMatchObject RegExp', () => {
  const x = {
    regexObject: new RegExp('foo'),
    regexLiteral: /bar/
  };

  expect(x).toMatchObject({
    regexObject: new RegExp('fizz'),
    regexLiteral: /buzz/
  });
});

Expected behavior

Test to fail because objects are different instances or because a serialized representation check failed.

Link to repl or repo (highly encouraged)

https://repl.it/talk/share/toMatchObject-with-RegExp-Objects/124058

jarruda avatar Feb 23 '21 21:02 jarruda

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Feb 17 '23 16:02 github-actions[bot]

This still looks valid.

jarruda avatar Feb 17 '23 20:02 jarruda

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Feb 17 '24 21:02 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] avatar Mar 18 '24 21:03 github-actions[bot]

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

github-actions[bot] avatar Apr 18 '24 00:04 github-actions[bot]