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

Ignore order of elements in list in JSON #208

Open
Majestry opened this issue Jul 19, 2021 · 1 comment · May be fixed by #287
Open

Ignore order of elements in list in JSON #208

Majestry opened this issue Jul 19, 2021 · 1 comment · May be fixed by #287
Labels
feature-request New feature or request

Comments

@Majestry
Copy link

Majestry commented Jul 19, 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.

@Thiht
Copy link
Collaborator

Thiht commented Jul 19, 2021

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 Thiht changed the title [FR] Ignore order of elements in list in JSON Ignore order of elements in list in JSON Sep 27, 2021
@Thiht Thiht added the feature-request New feature or request label Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
2 participants