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!
});
The argument to objectContaining(...) is not mutated.
Note: this link contains the very code described above ๐
This is the PR that seems to have broken it.
https://github.com/facebook/jest/pull/10508
Looks like we're mutating the object?
this.sample[property] = objectContaining(
this.sample[property] as Record<string, unknown>,
);
On Fri, Oct 23, 2020, 5:24 PM Floyd May, notifications@github.com wrote:
๐ 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 ๐
https://repl.it/repls/TomatoVengefulAngles#example.test.js
โ
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/facebook/jest/issues/10689, or unsubscribe
https://github.com/notifications/unsubscribe-auth/AOH4EJHBJZUZ3MHDMHATHGLSMHYCVANCNFSM4S5BVV5Q
.
Thank you all for addressing this so quickly! Do you know when I can expect a release that contains this fix?
today or tomorrow, need to fix #10690 first
fyi: for those waiting for a fix, for now, you can pin the expect package in the package.json :
"resolutions": {
"expect": "26.6.0"
}
Hoping to have a fix for #10690 this weekend, but if not I'll cut a release without it
Most helpful comment
Hoping to have a fix for #10690 this weekend, but if not I'll cut a release without it