Permalink
Browse files

Tests for clean cache option.

  • Loading branch information...
1 parent f204aca commit a25302511b22be1df3576bca8296565e40a2a829 @mfncooper committed Dec 29, 2012
Showing with 52 additions and 0 deletions.
  1. +7 −0 test/fixtures/intermediary.js
  2. +45 −0 test/mockery.functional.js
@@ -0,0 +1,7 @@
+var fake_module = require('./fake_module');
+
+var bar = function () {
+ return fake_module.foo();
+};
+
+exports.bar = bar;
View
@@ -464,6 +464,51 @@ module.exports = testCase({
})
})
})
+ }),
+
+ "when an intermediary module is involved": testCase({
+ "and mockery is not enabled": testCase({
+ "requiring the intermediary causes the original to be used": function (test) {
+ var intermediary = require('./fixtures/intermediary');
+ test.equal(intermediary.bar(), 'real foo');
+ test.done();
+ }
+ }),
+ "and mockery is enabled without the clean cache option": testCase({
+ setUp: function (callback) {
+ mockery.registerMock('./fake_module', mock_fake_module);
+ mockery.registerAllowable('./fixtures/intermediary');
+ mockery.enable({ useCleanCache: false });
+ callback();
+ },
+
+ "requiring the intermediary causes the original to be used": function (test) {
+ var intermediary = require('./fixtures/intermediary');
+ test.equal(intermediary.bar(), 'real foo');
+ test.done();
+ }
+ }),
+ "and mockery is enabled with the clean cache option": testCase({
+ setUp: function (callback) {
+ mockery.registerMock('./fake_module', mock_fake_module);
+ mockery.registerAllowable('./fixtures/intermediary');
+ mockery.enable({ useCleanCache: true });
+ callback();
+ },
+
+ "requiring the intermediary causes the mock to be used": function (test) {
+ var intermediary = require('./fixtures/intermediary');
+ test.equal(intermediary.bar(), 'mocked foo');
+ test.done();
+ }
+ }),
+ "and mockery is disabled": testCase({
+ "requiring the intermediary causes the original to be used": function (test) {
+ var intermediary = require('./fixtures/intermediary');
+ test.equal(intermediary.bar(), 'real foo');
+ test.done();
+ }
+ })
})
});

0 comments on commit a253025

Please sign in to comment.