【发布时间】:2016-01-05 00:48:11
【问题描述】:
我正在尝试在 Node.JS 上使用 Mocha 和 Chai 创建单元测试。这是要测试的函数的简化版本:
router.cheerioParse = function(url, debugMode, db, theme, outCollection, _callback2) {
var nberror = 0;
var localCount = 0;
console.log("\nstarting parsing now : " + theme);
request(url, function(error, response, body) {
//a lot of postprocessing here that returns
//true when everything goes well)
});
}
这是我正在尝试编写的测试:
describe('test', function(){
it('should find documents', function(){
assert( true ==webscraping.cheerioParse("http://mytest.com, null, null, null ,null,null ));
});
})
request 函数如何返回 true 以使其通过测试?我曾尝试使用承诺,但它也没有奏效。在这种情况下,我应该将 return 语句放在 then 回调中吗?最好的方法是什么?
【问题讨论】:
标签: javascript node.js mocha.js chai