我正在使用chaiHttp来测试API:
describe('Get Sensors', () => {
it('sensors are returned as an array', async () => {
let res = await chai.request(baseUrl).get(`/test`)
res.should.have.status(200);
});
});
这很好,除非发生异常:
AssertionError: expected { Object ...} to have status code 200 but got 500
+ expected - actual
-500
+200
at Proxy.<anonymous> (node_modules/chai-http/lib/http.js:83:10)
at Proxy.methodWrapper (node_modules/chai/lib/chai/utils/addMethod.js:57:25)
at Context.it (test/sensor.test.js:47:23)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:160:7)
该错误消息对调试API不太有用。 如何显示HTTP响应错误的内容? 它通常包含有关错误的更多说明。 我可以将所有测试包装在try / catches中,但这似乎很麻烦。