0

我正在尝试使用 mocha 对外部 HTTP 资源进行简单测试。这是我的代码:

describe('bing.com', function() {
    it('should return 200 for a GET request', function() {
        var requestify = require('requestify');

        requestify.get('http://bing.com')
            .then(function(response) {
                // Get the response body (JSON parsed or jQuery object for XMLs)
                console.log(response.getBody());
                done();
            });
    });
});

测试只是说通过了,但我的console.log电话从未显示。mocha 是否在收到 http 响应之前完成?

4

1 回答 1

1

您没有为done您的测试函数提供回调:

describe('bing.com', function() { it('should return 200 for a GET request', function(done) { ...

要捕获这样的错误,您应该使用 JSHint(或 Jslint)检查您的代码。两者都会通知您,done()由于未定义变量,您的调用将不起作用。

于 2014-06-05T05:43:12.113 回答