Skip to content

Instantly share code, notes, and snippets.

@ylv-io
Created April 26, 2019 10:12
Show Gist options
  • Save ylv-io/0019d7fb0148372e66c4413b5dce3edc to your computer and use it in GitHub Desktop.
Save ylv-io/0019d7fb0148372e66c4413b5dce3edc to your computer and use it in GitHub Desktop.
// in order to properly stub and mock libs which export function by default
// more https://github.com/sinonjs/sinon/issues/562
export const cache = {};
export default function(lib) {
const module = require(lib);
if (!cache.hasOwnProperty(lib)) cache[lib] = module;
return () => cache[lib].apply(this, args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment