0

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();
    });
});
4

1 に答える 1

0

asyncTest正直なところ、この API は後付けのように見えますが、テストではなく、探していると思います。

https://github.com/kof/node-qunit/blob/master/test/api.js#L107-115

このモジュールのファンではありません。

于 2011-09-27T20:27:11.227 に答える