notonthehighstreet/breadboard

View on GitHub
lib/autoMock.js

Summary

Maintainability
A
0 mins
Test Coverage
const sinon = require('sinon');

module.exports = (breadboardModule, options) => {
  const sandbox = sinon.sandbox.create();
  const mocks = options && options.mocks || {};
  const deps = Object.assign({}, mocks);
  const depsProxy = new Proxy(deps, {
    get(target, name) {
      if (!(name in target)) {
        deps[name] = sandbox.stub();
      }
      return deps[name];
    }
  });

  return {
    subject: breadboardModule(depsProxy),
    deps: depsProxy,
    sandbox: sandbox
  };
};