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

toEqual giving false positives when comparing objects in arrays #53

Closed
xbili opened this issue Dec 15, 2015 · 7 comments
Closed

toEqual giving false positives when comparing objects in arrays #53

xbili opened this issue Dec 15, 2015 · 7 comments

Comments

@xbili
Copy link

xbili commented Dec 15, 2015

Hi there! I've been playing around with this for a bit and found out that toEqual returns false positives when comparing objects inside arrays.

Refer to the example below:

let arr1 = [
  {
    id: 0,
    text: 'Array Object 0',
    boo: false
  },
  {
    id: 1,
    text: 'Array Object 1',
    boo: false
  }
];

let arr2 = [
  {
    id: 0,
    text: 'Array Object 0',
    boo: true // value of boo is changed to true here
  },
  {
    id: 1,
    text: 'Array Object 1',
    boo: false
  }
];

expect(arr1).toEqual(arr2);

console.log('All tests passed.');

The above test pass just fine, I am not sure if it's an intended behaviour. Anyone else facing similar issues? Thanks! 😄

@Poplava
Copy link

Poplava commented Dec 15, 2015

I got the same problem when I tested arguments which contains objects.
I think it would be helpful to have deepEqual for arrays and array-like objects with complex data structures inside.

mjackson added a commit that referenced this issue Dec 16, 2015
Illustrates the problem described in #53
@mjackson
Copy link
Owner

I recently made the switch to is-equal from deep-equal so that we can support ES2015 Map and Set comparisons, but it seems we have regressed in a few cases. I've added a failing test.

/cc @ljharb

@ljharb
Copy link
Collaborator

ljharb commented Dec 16, 2015

Sorry about this! I'll fix it ASAP.

@ljharb
Copy link
Collaborator

ljharb commented Dec 16, 2015

Fixed and released as v1.4.2.

@mjackson
Copy link
Owner

🎉 Thanks, @ljharb!

mjackson added a commit that referenced this issue Dec 16, 2015
Illustrates the problem described in #53
@mjackson
Copy link
Owner

Fixed and released in version 1.13.4

@xbili
Copy link
Author

xbili commented Dec 17, 2015

Thanks! @ljharb and @mjackson! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants