Skip to content

Instantly share code, notes, and snippets.

@jbreckmckye
Created April 11, 2017 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbreckmckye/8f1880adb1c4e9900427601b500f960c to your computer and use it in GitHub Desktop.
Save jbreckmckye/8f1880adb1c4e9900427601b500f960c to your computer and use it in GitHub Desktop.
Self-instantiating module constructors
function Module(lodash, THREE, moment) {
this.thingy = stuff => lodash.zip(stuff, false);
this.majig = whatever => moment().format(whatever);
this.zxzzxz = blah => new THREE.TextureLoader().load(blah);
}
module.exports = new Module(
require('lodash'),
require('three'),
require('moment')
);
const Module = require('./module').constructor;
const mockLodash = mocker();
const mockThree = mocker();
const mockMoment = mocker();
const withMocks = new Module(mockLodash, mockThree, mockMoment);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment