feat: allow non-object matchers for array-contains#459
Conversation
|
While this is a trivial change, I'm unsure that it would work correctly. If the variant is an array (like Is this what you require? |
This seems to be consistent with the rest of pact. If I wanted to check that a sub-array contained certain items in no particular order, I would be able to specify further "array-contains" matchers in a nested fashion, something like: Match.ArrayContains([
Match.ArrayContains(["A", "B"]),
Match.ArrayContains(["C", "D"]),
])As you say, if I specified just the arrays, they would need to match in the specified order: Match.ArrayContains([
new[] { "A", "B" },
new[] { "C", "D" },
])Not sure what kind of use case would require nested array-includes, but nonetheless I think this change makes it possible to specify both restrictions Can see this as a test case I added to a fork of PactNet running on top of the changes in this PR |
|
Awesome, I'll merge it. |
I have recently been writing a lot of pact tests and I noticed that the array-contains matcher requires each variant to be an object.
Reading the spec, it says "Checks if all the variants are present in an array".
Based on this, and the below implementation guides, it seems that non-object types should be supported too.
Having given the code base a cursory review, it seems that supporting this should be quite trivial.
Note: this is my first PR here so please let me know if there are steps I have missed