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 compares Set object rather than contained values #4286

Closed
thomas-mcdonald opened this issue Aug 17, 2017 · 2 comments
Closed

toEqual compares Set object rather than contained values #4286

thomas-mcdonald opened this issue Aug 17, 2017 · 2 comments
Labels

Comments

@thomas-mcdonald
Copy link

thomas-mcdonald commented Aug 17, 2017

This is a bug or feature request, depending on how you interpret the docs.

What is the current behavior?

I would expect

expect(new Set(["a", "b", "c"])).toEqual(new Set(["c", "a", "b"]));

to pass. Instead,

  ● groupResourcesByAcl › correctly groups set values together

    expect(received).toEqual(expected)

    Expected value to equal:
      Set {"c", "a", "b"}
    Received:
      Set {"a", "b", "c"}

repl.it reproduction

What is the expected behavior?

I would expect toEqual to perform comparison on the values the set contains, not the Set object. This is observable in lodash:

_.isEqual(new Set(["a","b","c"]), new Set(["c","b","a"]))
> true

It appears the equal matcher in Jest is defined in jasmine_utils, which seems to have been updated to handle sets in upstream - but the function is a bit of a wall of logic for me to feel comfortable just opening a PR with it updated. I'm also unsure if there are other places that would need to be updated for Set value comparison.

https://github.com/jasmine/jasmine/blob/6d0f0ed9150c2bf3d9c454b3ff464bab4119a65a/src/core/matchers/matchersUtil.js#L273-L304

@rogeliog
Copy link
Contributor

I think this line in the Jest codebase might be a good place to start 😄 https://github.com/facebook/jest/blob/master/packages/jest-matchers/src/matchers.js#L434

@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
Projects
None yet
Development

No branches or pull requests

4 participants