Closed
Description
🐛 Bug Report
When upgrading from react-scripts version 3.4.3 to version 4.0.0, jest was also upgraded. Tests that were behaving reasonably began failing. Upon closer inspection, I discovered that expect.objectContaining(...)
was mutating properties of the argument! For example, this code would fail in the indicated location:
test('adds 1 + 2 to equal 3', () => {
const thing = { foo: [{ val: 1}], bar: 2 };
const originalThing = { ...thing };
const json = JSON.stringify(originalThing);
expect(originalThing).toEqual(expect.objectContaining(thing));
expect(json).toEqual(JSON.stringify(thing)); // kaboom!
});
Expected behavior
The argument to objectContaining(...)
is not mutated.
Link to repl or repo (highly encouraged)
Note: this link contains the very code described above 😄