I've been working through the pact-js-mocha example and I'm having some difficulty verifying an interaction when the expected response is an error. This is the interaction I would like to verify:
PactConsumer(PactOpts, function () {
addInteractions([{
state: 'i have a list of projects',
uponReceiving: 'a bad request for projects',
withRequest: {
method: 'get',
path: '/projects'
},
willRespondWith: {
status: 400,
headers: { 'Content-Type': 'application/json; charset=utf-8' },
body: { reply: 'this is a 400' }
}
}])
verify('a 400 is returned', expectError, function (result, done) {
expect(JSON.parse(result)).to.eql({ reply: 'this is a 400' })
})
finalizePact()
})
However I'm not sure about the expectError() function. In the examples this returns a superagent request however when the status is set to 400 in the interaction the method seems to throw the error.
I've tried a few things but it has mostly been trail and all been error (things like using supertest to create a request and expecting on it's result).
Thanks for your help