Open carlnordenfelt opened 8 years ago
I would like this functionality, as well. I would consider an unregistered require to be an error, not a warning.
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);
}
};
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 });