和Sinon
工作Mocha
我在我的代码的NodeJS两种方法一样“this”引用不
function method1(id,callback){
var data = method2();
callback(null,data);
}
function method2(){
return xxx;
}
module.exports.method1 = method1;
module.exports.method2 = method2;
测试函数方法1,我不得不stub
方法方法2。 为此需要使用此测试用例通过调用方法方法2是
function method1(id,callback){
var data = this.method2();
callback(null,data);
}
试验规程这个
describe('test method method2', function (id) {
var id = 10;
it('Should xxxx xxxx ',sinon.test(function(done){
var stubmethod2 = this.stub(filex,"method2").returns(data);
filex.method1(id,function(err,response){
done();
})
})
})
,但停止代码错误工作this.method2不是功能。
有什么办法可以摆脱this
或module.exports
这似乎越野车。
请让我知道如果我错过了任何其他信息..
你能提供完整的测试文件代码吗? – semanser
你有这个工作吗? – alexi2
没有像代码工作或测试用例一样权衡 – mukul