We're using require
and Browserify, so single-function modules are imported like this:
var loadJson = require('../loadJson');
and used like this:
x = loadJson(url);
I'd like to spyOn
that loadJson function, but it doesn't seem to be possible.
It's not a global function, so this doesn't work:
spyOn(window, 'loadJson')
It's not a local function, so this doesn't work:
loadJson = createSpy('loadJsonSpy', loadJson).and.callThrough();
When I require
the module into my Jasmine spec, the function is visible inside that closure, but that's not the same closure as the other module which are actually using loadJson
for real.
So in short, I think it's not possibly to use spyOn
in this case - is that correct? Any creative workarounds?