和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