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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

expect.objectContaining(...) mutates properties of the argument #10689

Closed
floyd-may opened this issue Oct 23, 2020 · 7 comments 路 Fixed by #10711
Closed

expect.objectContaining(...) mutates properties of the argument #10689

floyd-may opened this issue Oct 23, 2020 · 7 comments 路 Fixed by #10711

Comments

@floyd-may
Copy link

馃悰 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

@dylang
Copy link
Contributor

dylang commented Oct 26, 2020

This is the PR that seems to have broken it.
#10508

Looks like we're mutating the object?

this.sample[property] = objectContaining(
  this.sample[property] as Record<string, unknown>,
);

@danfriesen383

This comment has been minimized.

@floyd-may
Copy link
Author

Thank you all for addressing this so quickly! Do you know when I can expect a release that contains this fix?

@SimenB
Copy link
Member

SimenB commented Oct 26, 2020

today or tomorrow, need to fix #10690 first

@peter-mouland
Copy link

fyi: for those waiting for a fix, for now, you can pin the expect package in the package.json :

  "resolutions": {
    "expect": "26.6.0"
  }

@SimenB
Copy link
Member

SimenB commented Oct 30, 2020

Hoping to have a fix for #10690 this weekend, but if not I'll cut a release without it

gnarea added a commit to relaycorp/relaynet-cogrpc-js that referenced this issue Nov 2, 2020
@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants