-
Notifications
You must be signed in to change notification settings - Fork 67
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
support json comparison in assertions #3684
Comments
It makes sense. On the inner objects case, I would add one more case: a
or even like this:
|
I think the first option is easier to get a grasp of. Assertions already support arrays, so that would be an easier change to introduce |
Looks good. Just one comment, I think the expect( [{foo: 'bar'}, {baz: 1, extra: 'quux'}] ).toMatchObject([
{foo: 'bar'},
{baz: 1},
]); |
@jorgeepc I think it would be very interesting to research how jest is doing it |
From jest
|
This was done and released in v0.16.0 Closing the ticket |
Describe the enhancement you'd like to see
Comparing all important data from a large JSON object can be cumbersome. In JS testing tools, they have an assertion function to check if an object is a subset of another, with this approach they gain two advantages:
I suggest we implement something like that. We could even use the existing
contains
comparator to compare two JSON objects.Rules
This would only be a JSON comparison if both sides of the statement are resolved as strings and can be parsed as JSON.
Examples
1. Order of attributes don't matter
2. Inner objects can be partially compared as well
Additional context
This was asked by one of our users in our Community Slack workspace.
The text was updated successfully, but these errors were encountered: