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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expect().toEqual gives false equivalencies for Immutable Records #4472

Closed
dclowd9901 opened this issue Sep 12, 2017 · 2 comments
Closed

Expect().toEqual gives false equivalencies for Immutable Records #4472

dclowd9901 opened this issue Sep 12, 2017 · 2 comments

Comments

@dclowd9901
Copy link

Recently upgraded to Jest 21.0.2, and some equality tests relating to comparing Immutable Records started failing.

I was able to trace the problem back to a utility called iterableEquality.

It turns out that iterable equality falsely identifies Immutable Records as iterables (likely because of this line):

  if (a.size !== undefined) { // Immutable Records also have a size prop

since IRs (Immutable Records) have a size property.

It then constructs a new object out of the properties of the compared objects (by combining them in an array and passing that array to the constructor of the a property), but merely compares the size of the newly constructed Record to the old a record and nothing else. It seems that when constructing a new Record out of the merged properties, Immutable uses the first reference listed in the array, not the second, to build the Record.

That means that if you have two Immutable Records of any kind that have the same properties, (nevermind the contents of those properties), this test will erroneously pass and not bother to look deeper in the records.

The real concern here is that the duck-typing utilized in iterableEquality is brittle, and subject to whether or not two constructed objects have a size param, and how they construct themselves.

Workaround: Convert Immutable Records to plain JSON objects and compare those instead, or stringify them and do the same.

Jest: 21.0.2
Node: 8.4.0
npm: 5.3.0

@cpojer
Copy link
Member

cpojer commented Sep 13, 2017

See #4404.

@cpojer cpojer closed this as completed Sep 13, 2017
@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 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants