1
我想用茉莉花來spyOn其中出口直接的方法的模塊:如何spyOn的NodeJS模塊單茉莉
Mymodule中
module.exports = (arg, arg) => {
//do something...
callAMethod();
//return
}
茉莉花
spyOn(myModule);
// since I don't have any method to use spyOn(myModule, <method>)
我發現我可以使用這個:
//describe..
var myModule = require('./myModule');
it...
myModule = jasmine.createSpy().and.callFake(function() {
return false;
}); // <-this should work
functionBeingTested(..args);
expect(myModule).toHaveBeenCalled(); /*I get false, even if
it is actually called
in the functionBeingTested*/
我發現的另一個解決方案是spyOn myModule.prototype
或設置jasmine.createSpy().and.returnValue(false)
但我都沒有成功。
我如何使用spyOn像我上面所說的?