Using Jasmine to `spyOn` a function in a (different) closure -


we're using require , browserify, single-function modules imported this:

var loadjson = require('../loadjson'); 

and used this:

x = loadjson(url); 

i'd spyon loadjson function, doesn't seem possible.

it's not global function, doesn't work:

spyon(window, 'loadjson') 

it's not local function, doesn't work:

loadjson = createspy('loadjsonspy', loadjson).and.callthrough(); 

when require module jasmine spec, function visible inside closure, that's not same closure other module using loadjson real.

so in short, think it's not possibly use spyon in case - correct? creative workarounds?

if loadjson singleton, can this.

var functionstospyon = {loadjson: loadjson} spyon(functionstospyon, 'loadjson') 

this workaround used when had same problem.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -