jest
jest copied to clipboard
toMatchObject passes with non-matching RegExp objects
🐛 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
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.
This still looks valid.
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.
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.
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.