thlorenz / proxyquireify

browserify >= v2 version of proxyquire. Mocks out browserify's require to allow stubbing out dependencies while testing.
MIT License
152 stars 24 forks source link

v3.1.0 breaks our tests #50

Closed hayesmaker closed 8 years ago

hayesmaker commented 8 years ago

Since the recent 3.1.0 update our tests get broken with a noCallThru error:

TypeError: 'undefined' is not an object (evaluating 'stub['@noCallThru']')

   at file:///Users/hayesmaker/Workspace/contracts/high5/online/client_code/HTML5/CasinoEngine/build/js/tests.js:26124

here's the area it refers to from our browserify bundle:,, the actual error comes form this line:

var noCallThru = stubWideNoCallThru || !!stub['@noCallThru'];

proxyquire._proxy = function (require_, request) {
  function original() {
    return require_(request);
  }

  if (!stubs || !stubs.hasOwnProperty(request)) return original();

  var stub = stubs[request];

  if (stub === null) throw moduleNotFoundError(request)

  var stubWideNoCallThru = !!stubs['@noCallThru'] && stub['@noCallThru'] !== false;
  var noCallThru = stubWideNoCallThru || !!stub['@noCallThru']; //
  return noCallThru ? stub : fillMissingKeys(stub, original());
};

and our test setup is written like this:

var stubs = {
  'group-manager': mocks.utils.layout.groupManager,
  'tween-utils': mocks.utils.effects.tweenUtils,
  'particle-manager': mocks.components.effects.particleManager,
  './transition-builder': mocks.components.bonus.transitionBuilder,
  '../../commands/features/spin-engines/spinning': mocks.commands.features.spinEngines.spinning,
  'asset-manager': mocks.utils.layout.assetManager,
  '../../utils/locale/number-formatter': mocks.utils.locale.numberFormatter,
  './spin-counter': mocks.components.bonus.spinCounter,
  '../background/background': mocks.components.background,
  '../../models/matrix': mocks.models.matrix,
  './award': mocks.components.bonus.award,
  '../../state-machine/decisions/is-replay': mocks.stateMachine.decisions.isReplay
};
var proxyquire = require('proxyquireify')(require);
var BonusSequence = proxyquire('../../../app/components/bonus/bonus-sequence', stubs);
hayesmaker commented 8 years ago

this is a breaking change from "proxyquireify": "~3.0.1"