[英]supertest-as-promised and chai
我尝试使用蔡志明所期望的超级测试。 测试应该是这样的:在foos
端点上发布一些JSON,然后调用bars
端点,其中响应的主体长度为2。
it('should fail', function(){
var agent = request(app)
agent
.post('/foos')
.send({
// some JSON
})
.then(function(){
agent.get('/bars').then(function(res){
console.log(res);
expect(res).to.have.deep.property('body.data').and.have.property('length').and.equal(3)
})
})
})
console.log无法运行,并且无论我写的是什么,测试都通过。
您确定您的诺言能够兑现吗? 首先,使用完成的回调检查此消息,以通知chai您的异步函数已完成:
it('should fail', function(done){
var agent = request(app)
agent
.post('/foos')
.send({
// some JSON
})
.then(function(){
agent.get('/bars').then(function(res){
console.log(res);
expect(res).to.have.deep.property('body.data').and.have.property('length').and.equal(3)
done();
}, function(error) {
console.log(error);
})
}, function(error) {
console.log(error);
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.