Édouard Lopez
09/26/2022, 2:24 PMnull OR string with the matchers?Timothy Jones
09/26/2022, 3:04 PMnull, no matcher is required
2) To match any string, use string()Timothy Jones
09/26/2022, 3:05 PMTimothy Jones
09/26/2022, 3:05 PMTimothy Jones
09/26/2022, 3:05 PMTimothy Jones
09/26/2022, 3:06 PMor types, then you might incorrectly pass when your provider never actually returns the stringTimothy Jones
09/26/2022, 3:08 PMTimothy Jones
09/26/2022, 3:17 PMnull in a payload is an anti-pattern. Null isn’t really a member of string, and if you let it be nullable, then you have to write null checks everywhere. Often then you end up with const someVar = response?.property?.field, where each thing that could be null has a different meaning, but they’ve all collapsed to one very hard to reason about variable (what does it mean if someVar is null?). This makes bugs hard to find, as you can’t easily tell the difference between “missing” and a programmer mistake. And allowing this kind of pattern discourages thinking about the unhappy path.
I prefer explicit typing, where you would be able to reason about which fields must be present on each type of object, or you might have a reasonable default for fields that are not present - do you really need to have null and ""? I think this in general leads to better designed APIs.
Of course, you didn’t come here to ask if null should be in your payload - the above is all my opinion, and you can totally use pact to test payloads that are nullable. However, you’ll have to write a separate test for it, because if pact allowed an OR field, then you couldn’t be sure you’d verified it.Édouard Lopez
09/27/2022, 10:54 AMnull and ""