tôi có mã này sử dụng supertest và mocha:Làm cách nào để tôi gặp lỗi máy chủ thực khi chạy supertest trong 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');
});
...
})
});
Khi mã máy chủ ném một số ngoại lệ (ví dụ như truy cập vào các thuộc tính của một đối tượng không xác định) tôi nhận được đống này dấu vết
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)
thay vì thực tế lỗi có nội dung "truy cập thuộc tính không xác định". Làm thế nào tôi có thể nhận được lỗi thực tế?
Câu hỏi hay, có vẻ như các thử nghiệm đơn vị cũ đơn giản gọi là chức năng thực tế có thể tốt hơn để theo dõi sự cố? Hoặc có thể có một sự kết hợp của supertests và thử nghiệm đơn vị: / –