【发布时间】:2016-03-15 20:53:42
【问题描述】:
我正在使用带有 mocha 的 supertest 来测试 nodejs express 应用程序。一切都很好,希望我想要更多描述性的错误消息。这并不是说这些消息目前不好,它们不是。我只是想了解更多信息。
例如:
it('should successfully post my data and return a valid JSON', function(done) {
.post(url)
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.send(data)
.expect(201, resultBody)
.end(function(err, res) {
if (err) return done(err);
done();
});
});
如果发生错误,导致 resultBody 与实际结果不匹配,它将打印出漂亮的+ expected - actual 消息。但我还想查看其他信息(可能是身份验证或标题)。
我目前的解决方案是执行以下操作:
.end(function(err, res) {
if (err) {
console.log(res.headers);
console.log(res.statusCode);
console.log(res.body);
return done(err);
}
done();
});
但是console.log 消息与“it”消息内联显示,在传递/挂起/失败消息之前,而不是实际错误。
是否可以在不费力气的情况下在错误消息中添加额外的信息?
【问题讨论】:
标签: node.js mocha.js supertest