0
我正在嘗試爲node.js庫,code.js編寫簡單的qunit測試。第一個測試用例是我嘗試的最簡單的測試用例,不會在我的code.js庫中使用任何導出的函數,但它不起作用。在node.js中用qunit測試http.get()
的QUnit模塊如下:
module = QUnit.module
var = http.require('http');
test("client test", function(){
expect(1);
var options = {
host: 'www.google.es',
port: 80,
path: '/'
}
http.get(options, function(res){
ok(true, "http.get callback success");
});
});
我認爲,問題之一是,GET回調之前的測試執行完成被執行,但我真的不知道。也許其餘的問題是,我是一個初學者,所以我會真正讚揚任何評論。
解決方案:我會用一個asyncTest:
asyncTest("client test", function(){
expect(1);
var options = {
host: 'www.google.es',
port: 80,
path: '/'
}
http.get(options, function(res){
ok(true, "http.get callback success");
start();
});
});
當然,我需要使用asyncTest,我已經嘗試過,但沒有正確的方式。因此,爲了用QUnit成功編寫異步測試,必須在斷言之後調用start()。我將編輯我的問題以發佈工作代碼。 – dysfuntcional