Created
May 24, 2016 15:58
-
-
Save atleastimtrying/b43ac1ba3507ac8eed90cdf5b824718b to your computer and use it in GitHub Desktop.
Dependency injection for an another library in requires
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(library){ | |
var get = function(url, callback){ | |
library.some_get_fn(url, 'additional param', callback); | |
}; | |
return { | |
get: get | |
}; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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