When using Express in a route or middleware, you can halt the callback chain by calling next(err) with any object as err. This feature is well-documented and simple to understand.
However, I encountered an issue when testing this behavior with SuperTest. Instead of receiving the error object specified in the middleware, the response only shows [object Object]
.
For instance:
const request = require('supertest');
const app = express();
app.use( (req, res, next) => next({ error: "ErrorCode" }) );
request(app).get('/')
.expect(500)
.end(function(err, res) {
// err == undefined
// res.text === '[object Object]'
});
Is there a way to verify the object passed to the next() callback when using SuperTest?
Although I could resort to using sinon+chai or jasmine for unit testing, I'm curious if SuperTest alone offers a solution, perhaps with the help of additional custom middleware after the testable unit.