How to stub require() / expect calls to the “root” function of a module?
问题 Consider the following jasmine spec: describe("something.act()", function() { it("calls some function of my module", function() { var mod = require('my_module'); spyOn(mod, "someFunction"); something.act(); expect(mod.someFunction).toHaveBeenCalled(); }); }); This is working perfectly fine. Something like this makes it green: something.act = function() { require('my_module').someFunction(); }; Now have a look at this one: describe("something.act()", function() { it("calls the 'root' function