Skip to content

Instantly share code, notes, and snippets.

@dbushong
Created December 27, 2013 19:44
Show Gist options
  • Save dbushong/8151645 to your computer and use it in GitHub Desktop.
Save dbushong/8151645 to your computer and use it in GitHub Desktop.
Mini-lib to make exported libraries more stubbable w/ e.g. bondjs
###
replace yourlib's:
module.exports = { foo, bar }
with:
module.exports = require('./stubbable') { foo, bar }
now when some file does:
{ foo } = require './yourlib'
you can still stub it with:
yourlib = require './yourlib'
bond(yourlib._fns, 'foo').return 42
###
_ = require 'underscore'
module.exports = (baseExports) ->
_fns = {}
res = { _fns }
_.each baseExports, (val, name) ->
if _.isFunction val
_fns[name] = val
val = (args...) -> _fns[name] args...
res[name] = val
res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment