Skip to content

Instantly share code, notes, and snippets.

@max-winderbaum
Last active September 24, 2017 21:00
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save max-winderbaum/f9d33448445f0079673527ab6e12a6d1 to your computer and use it in GitHub Desktop.
Poor Man's Dependency Injection
import dep1 from '../dep1';
import dep2 from '../dep2';
const defaultDeps = {
dep1,
dep2,
};
export function _myModuleFactory({ dep1, dep2 } = defaultDeps) {
const myModule = {};
// Module code here
return myModule;
}
export default _myModuleFactory();
import { _myModuleFactory } from './depInj.js';
const mockDep1;
const mockDep2;
const testableMyModule = _myModuleFactory({
dep1: mockDep1,
dep2: mockDep2,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment