我试图使用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调用从未显示过。摩卡是否在收到http响应之前完成?
发布于 2014-06-05 05:43:12
您没有为测试函数提供done回调:
describe('bing.com', function() { it('should return 200 for a GET request', function(done) { ...
要捕获这样的错误,您应该使用JSHint (或Jslint)检查代码。这两种方法都会通知您,由于未定义变量,您的done()调用将无法工作。
https://stackoverflow.com/questions/24044940
复制相似问题