【发布时间】:2016-01-09 22:04:51
【问题描述】:
我有这段代码使用 supertest 和 mocha:
import request from 'supertest';
//....
var newGame;
describe('Creating game', function() {
beforeEach(function(done) {
request(app)
.post('/api/games')
.send({
owner: 'Mr. X',
})
.expect(201)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) {
return done(err);
}
newGame = res.body;
done();
});
});
describe('the created game', function() {
it('should name the specified owner', function() {
newGame.owner.should.equal('Mr. X');
});
...
})
});
当服务器代码抛出一些异常(例如访问未定义对象的属性)时,我会得到这个堆栈跟踪
Error: expected 201 "Created", got 500 "Internal Server Error"
at Test._assertStatus (D:\Codes\theApp\node_modules\supertest\lib\test.js:232:12)
at Test._assertFunction (D:\Codes\theApp\node_modules\supertest\lib\test.js:247:11)
at Test.assert (D:\Codes\theApp\node_modules\supertest\lib\test.js:148:18)
at Server.assert (D:\Codes\theApp\node_modules\supertest\lib\test.js:127:12)
at emitCloseNT (net.js:1521:8)
而不是实际的错误,例如“访问未定义的属性”。我怎样才能得到实际的错误?
【问题讨论】:
-
好问题,似乎调用实际函数的普通旧单元测试可能更好地追踪崩溃?或者也许有超级测试和单元测试的组合:/
-
您能否为我的答案不正确添加理由或将我的答案标记为正确。谢谢。
标签: node.js mocha.js supertest