Skip to content

Instantly share code, notes, and snippets.

@mfncooper
Created December 28, 2012 18:52
Show Gist options
  • Save mfncooper/4400759 to your computer and use it in GitHub Desktop.
Save mfncooper/4400759 to your computer and use it in GitHub Desktop.
When a module is 'require'd before mockery is enabled, mockery will still provide the mock when enabled, bypassing the cache entry.
var mockery = require('../mockery'),
fake_module;
var mock_fake_module = {
foo: function () {
return 'mocked foo';
}
};
fake_module = require('./fixtures/fake_module');
console.log("Should be real: " + fake_module.foo());
mockery.registerMock('./fixtures/fake_module', mock_fake_module);
mockery.enable();
fake_module = require('./fixtures/fake_module');
console.log("Should be mock: " + fake_module.foo());
mockery.disable();
mockery.deregisterAll();
fake_module = require('./fixtures/fake_module');
console.log("Should be real: " + fake_module.foo());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment