Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rewire.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBob Pace <bob.pace@gmail.com>2014-07-01 01:12:07 +0400
committerBob Pace <bob.pace@gmail.com>2014-07-01 01:12:07 +0400
commit74dcfece99ff75e36a4ea544885f7aab888a82cf (patch)
treefd22f0de9c10dd85fa5e8d6ceffe83ad5faf3606 /test
parentd4bc6505c0c116074bc89697b553decfea54dec5 (diff)
__set__ returns an 'undo' function that when invoked will restore the module to the values it had before it was called
Diffstat (limited to 'test')
-rw-r--r--test/__set__.test.js29
1 files changed, 26 insertions, 3 deletions
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
+});