diff options
-rw-r--r-- | lib/__set__.js | 2 | ||||
-rw-r--r-- | test/testModules/sharedTestCases.js | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/__set__.js b/lib/__set__.js index 83671a1..851a340 100644 --- a/lib/__set__.js +++ b/lib/__set__.js @@ -24,7 +24,7 @@ function __set__() { for (arguments.varName in arguments.env) { if (arguments.env.hasOwnProperty(arguments.varName)) { arguments.varValue = arguments.env[arguments.varName]; - arguments.src += arguments.varName + " = arguments.env." + arguments.varName + "; "; + arguments.src += arguments.varName + " = arguments.env[" + JSON.stringify(arguments.varName) + "]; "; arguments.revertArgs[0][arguments.varName] = eval(arguments.varName); } } diff --git a/test/testModules/sharedTestCases.js b/test/testModules/sharedTestCases.js index d482199..1e03d13 100644 --- a/test/testModules/sharedTestCases.js +++ b/test/testModules/sharedTestCases.js @@ -284,6 +284,18 @@ describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv + expect(rewiredModuleA.getMyObj()).to.eql({ test: undefined }); + + revert = rewiredModuleA.__set__({ + "myObj.test": true + }); + expect(rewiredModuleA.getMyObj()).to.eql({ + test: true + }); + revert(); + expect(rewiredModuleA.getMyObj()).to.eql({ + test: undefined + }); + }); }); |