【发布时间】:2016-06-09 14:46:39
【问题描述】:
我有一个看起来像这样的测试:
it('should fail to get deleted customer', function(done) {
request(app)
.get('/customers/'+newCustomerId)
.set('Authorization', 'Bearer ' + token)
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(404, done)
});
我已经阅读了这里的文档:
https://github.com/visionmedia/supertest
上面写着:
注意如何将 done 直接传递给任何 .expect() 调用
不起作用的代码行是.expect(404, done),如果我将其更改为.expect(200, done),那么测试不会失败。
但是,如果我添加这样的结尾:
it('should fail to get deleted customer', function(done) {
request(app)
.get('/customers/'+newCustomerId)
.set('Authorization', 'Bearer ' + token)
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
.end(function(err, res) {
if (err) console.log(err);
done();
});
});
然后测试失败。为什么.expect(200, done) 也没有失败?
【问题讨论】: