You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's assume, we expect the next payload to be sent in POST request, that should be caught by smocker: { "tags": ["hello1", "hello2", "hello3"] }
If i create the new mock and specify the shown json as body with matcher ShouldEqualJSON, it will work only if we receive the exactly same list in the same order.
If, for example, received body is { "tags": ["hello2", "hello1", "hello3"] }
then Smocker will not match it with configured mock and will return 666.
I propose to ignore the order of entries inside the list, since logically this is still the same list in both cases.
The text was updated successfully, but these errors were encountered:
Arrays are ordered so my opinion on this is that this is the correct behavior for JSON array equality.
However I see the need for this, maybe a new ShouldEqualJSONLoose or ShouldEqualJSONNonStrict operator would be a good idea? In the wild I found this lib which has a strict/non strict mode: https://github.com/skyscreamer/JSONassert
When strict is set to false (recommended), it forgives reordering data and extending results (as long as all the expected elements are there), making tests less brittle.
This seems like sane behaviours to implement in a Loose operator.
This is not trivial to implement though
Thiht
changed the title
[FR] Ignore order of elements in list in JSON
Ignore order of elements in list in JSON
Sep 27, 2021
Let's assume, we expect the next payload to be sent in POST request, that should be caught by smocker:
{ "tags": ["hello1", "hello2", "hello3"] }
If i create the new mock and specify the shown json as body with matcher ShouldEqualJSON, it will work only if we receive the exactly same list in the same order.
If, for example, received body is
{ "tags": ["hello2", "hello1", "hello3"] }
then Smocker will not match it with configured mock and will return 666.
I propose to ignore the order of entries inside the list, since logically this is still the same list in both cases.
The text was updated successfully, but these errors were encountered: