Hi, all. Does order of fields in response body mat...
# pact-js
i
Hi, all. Does order of fields in response body matters when executing pact verification? Today I faced with strange issue for the first time: looks like pact-js expecting that fields in json object will be in alphabetical order. For example, I compose my response body expectation, as it comes from API:
willRespondWith: {
……
objectN: {
fieldC: "valueC",
fieldA: "valueA",
fieldB: "valueB"
}
……
}
When contract file generated, it appears be sorted in alphabetical order in contract file:
response: {
……
objectN: {
fieldA: "valueA",
fieldB: "valueB",
fieldC: "valueC"
}
……
}
When verifying provider, it fails on verification of
objectN
. I cannot find any mismatches, except order of fields in
objectN
. Could someone help and explain me this? For example, if I want generated response body fields to be in same order as I defined? One of the latest versions of
@pact_foundation_greet/pact
in use (
"@pact-foundation/pact": "^10.4.1"
in
package.json
).
m
If you don’t use a matcher, yes I think it might do that.
i
What should I do?
I use matchers
like
,
eachLike
,
number
etc widely
Sorry, I found my error, nothing related to order, just typo
😆 2
m
no worries 🙂
t
It can’t be order dependent- json properties have no order
It might look different in the error output
i
Yes, @Timothy Jones thank you, I found issue already. It was 2 character misspelling I didn’t notice at first look
🙌 2
m
It can’t be order dependent- json properties have no order
💯 I thought I saw array items, which are order dependent (if you don’t use an “each like” type matcher. Thanks for clarifying Tim
👍 1