From 75ebdd4647c7cde033fd6d3c843d7235d69145bc Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Thu, 5 Feb 2015 21:30:15 +0100 Subject: Fix issues with reverting nested properties Fixes #39 --- test/testModules/sharedTestCases.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/testModules/sharedTestCases.js b/test/testModules/sharedTestCases.js index 20e017d..d482199 100644 --- a/test/testModules/sharedTestCases.js +++ b/test/testModules/sharedTestCases.js @@ -267,4 +267,23 @@ describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv + }).to.throwException(checkForTypeError); }); -}); \ No newline at end of file + it("should also revert nested changes (with dot notation)", function () { + var rewiredModuleA = rewire("./moduleA.js"), + revert; + + revert = rewiredModuleA.__set__("myObj.test", true); + expect(rewiredModuleA.getMyObj()).to.eql({ + test: true + }); + revert(); + // This test also demonstrates a known drawback of the current implementation + // If the value doesn't exist at the time it is about to be set, it will be + // reverted to undefined instead deleting it from the object + // However, this is probably not a real world use-case because why would you + // want to mock something when it is not set. + expect(rewiredModuleA.getMyObj()).to.eql({ + test: undefined + }); + }); + +}); -- cgit v1.2.3