diff options
author | Johannes Ewald <johannes.ewald@peerigon.com> | 2015-02-17 03:07:22 +0300 |
---|---|---|
committer | Johannes Ewald <johannes.ewald@peerigon.com> | 2015-02-17 03:07:22 +0300 |
commit | 39bf586fba7022a1a7cf61515ec45fad9dcbe846 (patch) | |
tree | dce7944da0601d9e5e8983d19857dffb158e9c05 /test | |
parent | 02a15ea0eeaa4059535abad14d15e20df82feea4 (diff) |
Add possibility to mock undefined, implicit globals
Fixes #35
Diffstat (limited to 'test')
-rw-r--r-- | test/testModules/implicitGlobal.js | 6 | ||||
-rw-r--r-- | test/testModules/sharedTestCases.js | 55 |
2 files changed, 52 insertions, 9 deletions
diff --git a/test/testModules/implicitGlobal.js b/test/testModules/implicitGlobal.js index 9bc3e2a..3048742 100644 --- a/test/testModules/implicitGlobal.js +++ b/test/testModules/implicitGlobal.js @@ -1,2 +1,6 @@ implicitGlobal = "this is an implicit global var ..." + - "yes, it's bad coding style but there are still some libs out there";
\ No newline at end of file + "yes, it's bad coding style but there are still some libs out there"; + +module.exports = function () { + return undefinedImplicitGlobal; +}; diff --git a/test/testModules/sharedTestCases.js b/test/testModules/sharedTestCases.js index 1e03d13..76498bd 100644 --- a/test/testModules/sharedTestCases.js +++ b/test/testModules/sharedTestCases.js @@ -249,16 +249,28 @@ describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv + }); it("should be possible to set implicit globals", function () { - var implicitGlobalModule = rewire("./implicitGlobal.js"); + var implicitGlobalModule, + err; - implicitGlobalModule.__set__("implicitGlobal", true); - expect(implicitGlobalModule.__get__("implicitGlobal")).to.be(true); - // setting implicit global vars will change them globally instead of locally. - // that's a shortcoming of the current implementation which can't be solved easily. - //expect(implicitGlobal).to.be.a("string"); + try { + implicitGlobalModule = rewire("./implicitGlobal.js"); + + implicitGlobalModule.__set__("implicitGlobal", true); + expect(implicitGlobalModule.__get__("implicitGlobal")).to.be(true); + // setting implicit global vars will change them globally instead of locally. + // that's a shortcoming of the current implementation which can't be solved easily. + //expect(implicitGlobal).to.be.a("string"); + } catch (e) { + err = e; + } finally { + // Cleaning up... + delete global.implicitGlobal; + delete global.undefinedImplicitGlobal; + } - // Cleaning up... - delete global.implicitGlobal; + if (err) { + throw err; + } }); it("should throw a TypeError if the path is not a string", function () { @@ -298,4 +310,31 @@ describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv + }); + it("should be possible to mock undefined, implicit globals", function () { + var implicitGlobalModule, + err; + + try { + implicitGlobalModule = rewire("./implicitGlobal.js"); + implicitGlobalModule.__set__("undefinedImplicitGlobal", "yoo!"); + expect(implicitGlobalModule.__get__("undefinedImplicitGlobal")).to.equal("yoo!"); + + implicitGlobalModule = rewire("./implicitGlobal.js"); + implicitGlobalModule.__set__({ + undefinedImplicitGlobal: "bro!" + }); + expect(implicitGlobalModule.__get__("undefinedImplicitGlobal")).to.equal("bro!"); + } catch (e) { + err = e; + } finally { + // Cleaning up... + delete global.implicitGlobal; + delete global.undefinedImplicitGlobal; + } + + if (err) { + throw err; + } + }); + }); |