I am using Pact for the first time and I would lik...
# pact-js
t
I am using Pact for the first time and I would like to write a test which does not specify a certain HTTP status code for the provider to respond with. As in as long as any 4xx error response is there, the test should pass. Is it possible?
Copy code
.willRespondWith({
  status: '4xx',
  headers: { 'Content-Type': 'application/json' },
  body: EXPECTED_BODY,
})
t
Not with Pact, as far as I know. The usual pattern is to just put one in the contract that you know it can generate.
ContractCase does support this, but the documentation isn’t complete yet, and it only supports JavaScript / Typescript at the moment: https://case.contract-testing.io/
t
Thanks @Timothy Jones! I wanted to keep it generic because as a consumer I didn’t care what the status code was but for now I used 406 which our backend actually returns. Honestly I didn’t want to look at the backend implementation to write my pact but it’s okay 😄
t
yeah, that’s a good pragmatic approach
general errors are an interesting case, because they’re kind of out of the contract - like, if your client isn’t relying on them, they don’t need to be in the contract. But, you also want them in the contract, so you can say “well, if you produce ANY errors, I want them in this format”
1