Created
December 28, 2012 18:52
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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