From 74dcfece99ff75e36a4ea544885f7aab888a82cf Mon Sep 17 00:00:00 2001 From: Bob Pace Date: Mon, 30 Jun 2014 15:12:07 -0600 Subject: __set__ returns an 'undo' function that when invoked will restore the module to the values it had before it was called --- test/__set__.test.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'test/__set__.test.js') diff --git a/test/__set__.test.js b/test/__set__.test.js index 7b9c2cb..ff1a3d2 100644 --- a/test/__set__.test.js +++ b/test/__set__.test.js @@ -69,8 +69,31 @@ describe("__set__", function () { expect(moduleFake.getValue()).to.be(2); expect(moduleFake.getReference()).to.be(newObj); }); - it("should return undefined", function () { - expect(moduleFake.__set__("myValue", 4)).to.be(undefined); + it("should return a function that when invoked reverts to the values before set was called", function () { + undo = moduleFake.__set__("myValue", 4) + expect(typeof undo).to.be("function"); + expect(moduleFake.getValue()).to.be(4); + undo() + expect(moduleFake.getValue()).to.be(0); + }); + it("should be able to revert when calling with an env-obj", function () { + var newObj = { hello: "hello" }; + + expect(moduleFake.getValue()).to.be(0); + expect(moduleFake.getReference()).to.eql({}); + + var undo = moduleFake.__set__({ + myValue: 2, + myReference: newObj + }); + + expect(moduleFake.getValue()).to.be(2); + expect(moduleFake.getReference()).to.be(newObj); + + undo(); + + expect(moduleFake.getValue()).to.be(0); + expect(moduleFake.getReference()).to.eql({}); }); it("should throw a TypeError when passing misfitting params", function () { expect(function () { @@ -101,4 +124,4 @@ describe("__set__", function () { moduleFake.__set__("someVar"); // misfitting number of params }).to.throwException(expectTypeError); }); -}); \ No newline at end of file +}); -- cgit v1.2.3