mercredi 4 mars 2015

How can I substitute variable in JS?

I'm trying to write unit-test. I have a simple module:



var Common = module.exports = {
unit: {
somejQueryFn: function() { $('.selector') /* work with jQuery */ }
}
}


Unit-test code:



describe('Test jQuery spec', function(){
var Common = require('common');
it('not working :( ', function(){
//Work. I'm using jsdom, for using jQuery in tests; It's a jQuery instance
expect( typeof $ ).toBe('function');

//$ is undefined in somejQueryFn;
expect( Common.unit.somejQueryFn() ).toBe( result );
})
})


So, how can I handle it? Any ideas? I have tried using new Function(), but i think that is not a good idea.


Aucun commentaire:

Enregistrer un commentaire