0
我陣列上運行的摩卡測試循環,像這樣:運行摩卡測試循環同步
it('each should have permissions defined for each role', function(done) {
async.forEach(_permissions, function(permission, callback) {
log.debug(permission.permissions.should.be.an.instanceOf(Array).and.not.be.empty);
callback(permission.permissions.should.be.an.instanceOf(Array).and.not.be.empty);
},
function(result) {
log.debug(result);
done();
});
});
當我登錄出來,看來即使我使用done()
回調異步運行。是這樣嗎?我的測試是否仍然成功執行,還是僅執行第一個測試,然後返回成功結果?
這裏是控制檯輸出:
[Tue Dec 02 2014 09:24:07 GMT-0800 (PST)] DEBUG { obj: [ 'permissions!' ], params: { operator: 'to be empty' }, negate: false }
✓ each should have permissions defined for each role // <- here's the test result
[Tue Dec 02 2014 09:24:07 GMT-0800 (PST)] DEBUG { obj: [ 'permissions!' ], params: { operator: 'to be empty' }, negate: false }
[Tue Dec 02 2014 09:24:07 GMT-0800 (PST)] DEBUG { obj: [ 'permissions!' ], params: { operator: 'to be empty' }, negate: false }
[Tue Dec 02 2014 09:24:07 GMT-0800 (PST)] DEBUG { obj: [ 'permissions!' ], params: { operator: 'to be empty' }, negate: false }
DOH!真棒;) – brandonscript 2014-12-02 17:37:55
它實際上是'eachSeries'?當我使用它時,現在只有一個測試執行。 – brandonscript 2014-12-02 17:41:17
啊,不得不稍微修改 - 斷言需要不在回調中。 – brandonscript 2014-12-02 17:44:59