Hello,
When expectations are not met (example: expected 201 "Created", got 500 "Internal Server Error"), it would be nice to log the response body, as it may contain information for fixing the problem.
Thanks
+1. This has been a pain for me and I've resorted to patching the _assertStatus method, which is undesirable. Something like this:
request.Test.prototype._assertStatus = function (status, res) {
if (res.status !== status) {
const expectedStatus = http.STATUS_CODES[status];
const actualStatus = http.STATUS_CODES[res.status];
let errorMessage = `expected ${status} "${expectedStatus}", got ${res.status} "${actualStatus}"`;
// Add a more useful error message.
if (res.body.error) {
errorMessage += ` and response error was: \'${res.body.error.message}\'`;
}
return new Error(errorMessage);
}
};
+1 Running into this as well :/
Thanks for the patch @RyanMcDonald - For me it seems to be res.error and not res.body.error, though.
@RyanMcDonald Thanks for that patch. I've created a small module that will un/patch supertest in a similar manner. It preserves the original implementation (making it less likely to break with an update).
See it here: https://gist.github.com/musicin3d/d2d0d63ff7062f40776d27db64ea77ba
Most helpful comment
+1. This has been a pain for me and I've resorted to patching the
_assertStatusmethod, which is undesirable. Something like this: