Skip to content

Instantly share code, notes, and snippets.

@atleastimtrying
Created May 24, 2016 15:58
Show Gist options
  • Save atleastimtrying/b43ac1ba3507ac8eed90cdf5b824718b to your computer and use it in GitHub Desktop.
Save atleastimtrying/b43ac1ba3507ac8eed90cdf5b824718b to your computer and use it in GitHub Desktop.
Dependency injection for an another library in requires
module.exports = function(library){
var get = function(url, callback){
library.some_get_fn(url, 'additional param', callback);
};
return {
get: get
};
};
var dummy_lib = {
some_get_fn: function(url, additional_param, callback){
}
};
var ajax = require('ajax')(dummy_lib);
it('calls out to dummy lib fn', function(){
spyOn(dummy_lib, 'some_get_fn');
ajax.get('foo', function(){});
expect(dummy_lib.some_get_fn).toHaveBeenCalled();
});
var ajax_lib = require('some-ajax-library');
var ajax = require('ajax')(ajax_lib);
ajax.get('/thing.json', function(){
console.log('!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment