Hello :wave:, in my team we are currently starting...
# pact-js
j
Hello 👋, in my team we are currently starting with contract tests using PactV3. The endpoint we are currently testing is expected to return an empty array
[]
, but also non-empty arrays. If the array is not empty, each entry should be of the same specific type. When we are using
eachLike({ourTypeMatcher}, 0)
, the pact file omits the type information (In contrast, with min value of 1
eachLike({ourTypeMatcher}, 1)
, the type information is stored in the pact file). How can we convey the information I described above?
m
You need to write two tests - one for the 0 case and one for the non-zero case
see below help article (howtooptional)
j
Thank your for your fast response, Matt! Okay, our endpoint returns time series data (or not) for each pair of timestamps it receives. So the right practice is to identify time intervals for which we expect no data and time intervals for which we expect data and write a test for each, right?
b
If you're testing against test/mock/stub data, then the state handler (however you set it up) should be able to fulfil those 2 scenarios. If you're testing against real data, then yes, you'll need to "identify time intervals for which we expect no data" etc, but that's a dangerous path.
(I guess, if you have a large amount of static mock data, and it's hard to pick apart, then you'll still have to find matching ranges without data, and it'll be more brittle than on-demand mock data, but less brittle than live data.)