开发者

testing http.get() with qunit in node.js

I'm trying to write a simple qunit test for a node.js library, code.js. The first test case is the simplest one i'm trying and doesn't use any exported function in my code.js library, but it doesn't work.

The QUnit module is as follows:

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 callbac开发者_开发知识库k success");
    });
});

I think that one of the problems is that the test execution finish before the get callback gets executed, but i'm not really sure. Maybe the rest of the problems are that i'm a beginner with qunit, so i'll really apreciate any comments.

Solution: I will use an 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();
    });
});


To be honest, this API appears to be an afterthought, but I think you're looking for asyncTest rather than test

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

Not a fan of this module.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜