Providing extra information in failure messages
This section improves the detailed information that is presented to the developer when a test fails. The purpose of this extra information is to help pinpoint the issue with the application code so that the developer isn’t left scratching their head about what went wrong.
Let’s begin:
- Add the next test, which checks that a basic message is shown when the response bodies do not match:
it('returns a message if the provided object does not match', () => { const response = fail(422, { a: 'b' }); expect(() => expect(response).toBeUnprocessableEntity({ c: 'd' }) ).toThrowError(/Response body was not equal/); });
- To make that pass, add the
message
property to the second guard clausereturn
value. We’ll expand on this in the next test:if (!this.equals(.....