Hi From the Doc here <https://github.com/pact-foun...
# pact-js
e
Hi From the Doc here https://github.com/pact-foundation/pact-specification/tree/version-3#allow-arrays-of-matchers-to-be-defined-against-a-matcher-path I see that multiple matchers are allowed in V3 and there is an option to specify
"combine": "AND",
or
"combine": "OR",
I'm interested in that feature, but I don't see how the I can apply it with pact-js. It always writes
"combine": "AND",
How can I achieve an OR-Combination of Matchers? The API I need to test provides Options of different types, and depending on the type, the type of the remaining fields change:
Copy code
{
    OPTION_A: {
        "type": "Number",
        "value": 0,
        "allowedValues": [
            0,
            500,
            1000,
            2000
        ]
    },
    OPTION_B: {
        "type": "String",
        "value": "No",
        "allowedValues": [
            "Yes",
            "No",
            "Maybe"
        ]
    }
}
message has been deleted
m
OR matcher was a controversial introduction at the time and the maintainer group have mostly decided it is a bad idea. It essentially allows you to write a contract the might fail. See also howtooptional as to why
e
I think in this case the OR would actually make sense. I want to write a method for a pact-js test-case that would give me the general structure of the response and for each specific test-case I can then overwrite details. Anyway, i would be happy to have the eachKeyLike() Matcher working properly, I can then get around not having OR.
👍 1
m
I like to quote @Timothy Jones on this
A pact test is not about describing the possible responses, it’s about ensuring that your response types are covered.
For example, if you could say “it might be a person or a team”, you could pass your tests without ever checking that the provider and consumer agree about what a Team should look like
Think of the matchers as saying “this test covers all cases that pass this matcher”, not “this is the response schema”
I think this should make it onto our “matchers” best practice guide
🙌 1
t
I think in this case the OR would actually make sense. I want to write a method for a pact-js test-case that would give me the general structure of the response and for each specific test-case I can then overwrite details.
This doesn’t sound like a good fit for an or matcher to me. If you don’t care about certain parts of the response in your test, just don’t include them
I think the OR matcher is an implementation detail, not part of the exposed API (on purpose).