diff options
author | Johannes Ewald <johannes.ewald@peerigon.com> | 2015-02-05 23:30:15 +0300 |
---|---|---|
committer | Johannes Ewald <johannes.ewald@peerigon.com> | 2015-02-05 23:30:15 +0300 |
commit | 75ebdd4647c7cde033fd6d3c843d7235d69145bc (patch) | |
tree | 455302383f60b2497781557c467329d9a64a9da2 /test | |
parent | 972972e405ee6aace9959723a2221c7e46fc7225 (diff) |
Fix issues with reverting nested properties
Fixes #39
Diffstat (limited to 'test')
-rw-r--r-- | test/testModules/sharedTestCases.js | 21 |
1 files changed, 20 insertions, 1 deletions
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 + }); + }); + +}); |