[英]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.