mfncooper / mockery

Simplifying the use of mocks with Node.js
Other
1.1k stars 60 forks source link

Fail on unregistered require #52

Open carlnordenfelt opened 8 years ago

carlnordenfelt commented 8 years ago

Would it be possible to add a config that will fail the run (i.e. throw an Error) if a module that is not registered either as a mock or as allowed is loaded? The warnOnUnregistered log output is very easy to miss if you want to be certain that you are not loading something by mistake, especially when the test suite is large.

Something like: mockery.enable({ throwOnUnregistered: true });

nivthefox commented 8 years ago

I would like this functionality, as well. I would consider an unregistered require to be an error, not a warning.

ludicruz commented 7 years ago

I would like this functionality as well. I have a hack in place for my test suite that I would like to get rid of at some point:

let warner = global.console.warn;

global.console.warn = function(warn) {
  warner.apply(arguments);
  if (/^WARNING: loading non-allowed module:/.test(warn)) {
    throw new Error(warn);
  }
};