我正在嘗試使用done();
調用寫一個asynchronous
測試與mocha
。這是我的代碼到目前爲止。然而如何使用mocha使用'done();'進行異步測試?
it('should have data.', function() {
db.put(collection, key, json_payload)
.then(function (result) {
result.should.exist;
done();
})
.fail(function (err) {
err.should.not.exist;
done();
})
})
其結果是,代碼只是執行,而無需等待爲當時還是無法與實際的結果返回。 done();
需要在代碼中的不同位置嗎?
還貼出了整個回購在這裏:https://github.com/Adron/node_testing_testing
糾正我,如果我錯了,但不傳遞給''''調用的函數需要'done'參數? '它(「應該具有的內容」,功能(完成){''與它(「應該具有的內容」,函數(){'[與摩卡測試異步函數](HTTP的 – juanpaco
可能重複:// stackoverflow.com/questions/12159846/testing-asynchronous-function-with-mocha) – Louis
@juanpaco是的,看看下面的答案被notmyself。 – Adron