【发布时间】:2019-01-12 03:22:19
【问题描述】:
当使用npm run test 运行 mocha 测试时,是否可以在测试失败并出现错误时打印响应正文的内容?
chai.request(server)
.post('/')
.set('X-Access-Token', testUser.accessToken)
.send(fields)
.end((error, response) => {
console.log(response.body); // log this!
response.should.have.status(201); // if this fails!
done();
});
});
换句话说,afterEach 函数能否访问每个测试的error 和response?
afterEach(function(error, response) {
if (error) console.log('afterEach', response.body);
});
我们在响应中有有用的错误消息,因此我们发现自己将 console.log 行粘贴到失败的测试中进行调试。总是能看到每个错误的 response.body 就好了。
【问题讨论】:
标签: node.js npm mocha.js response chai