node.js ライブラリ code.js の簡単な qunit テストを作成しようとしています。最初のテスト ケースは、私が試している最も単純なもので、code.js ライブラリでエクスポートされた関数を使用していませんが、機能しません。
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");
});
});
問題の 1 つは、get コールバックが実行される前にテストの実行が終了することだと思いますが、よくわかりません。残りの問題は、私が qunit の初心者であることにあるのではないでしょうか。
解決策: 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();
});
});