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

Suggest toMatchObject over toEqual(expect.objectContaining) #230

Closed
garyking opened this issue Mar 1, 2019 · 5 comments · Fixed by #575
Closed

Suggest toMatchObject over toEqual(expect.objectContaining) #230

garyking opened this issue Mar 1, 2019 · 5 comments · Fixed by #575

Comments

@garyking
Copy link
Contributor

garyking commented Mar 1, 2019

If expect().toEqual(expect.objectContaining) is the same as expect().toMatchObject() then perhaps have a rule to suggest the latter instead?

@SimenB
Copy link
Member

SimenB commented Mar 4, 2019

I wonder if we maybe want to go the other way? Would be nice to remove toMatchObject from Jest, as the asymmetric matcher provides the needed primitive?

/cc @thymikee

@thymikee
Copy link
Member

thymikee commented Mar 4, 2019

It's more writing though, I'm not sure if people would like it. We could start with something like prefer-object-containing though

@rdsedmundo
Copy link

Those matchers from time to time lead me into confusion with respect to each one to use, the differences between both, etc.

And it's not just me (20k views): https://stackoverflow.com/questions/45692456/whats-the-difference-between-tomatchobject-and-objectcontaining

@garyking
Copy link
Contributor Author

@rdsedmundo Yes I absolutely agree. That's why I wrote a rule for myself, for the moment, which prefers objectContaining over toMatchObject, with the reason being that the former is more strict.

@github-actions
Copy link

🎉 This issue has been resolved in version 23.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

4 participants