@@ -69,8 +69,31 @@ describe("__set__", function () {
69
69
expect ( moduleFake . getValue ( ) ) . to . be ( 2 ) ;
70
70
expect ( moduleFake . getReference ( ) ) . to . be ( newObj ) ;
71
71
} ) ;
72
- it ( "should return undefined" , function ( ) {
73
- expect ( moduleFake . __set__ ( "myValue" , 4 ) ) . to . be ( undefined ) ;
72
+ it ( "should return a function that when invoked reverts to the values before set was called" , function ( ) {
73
+ undo = moduleFake . __set__ ( "myValue" , 4 )
74
+ expect ( typeof undo ) . to . be ( "function" ) ;
75
+ expect ( moduleFake . getValue ( ) ) . to . be ( 4 ) ;
76
+ undo ( )
77
+ expect ( moduleFake . getValue ( ) ) . to . be ( 0 ) ;
78
+ } ) ;
79
+ it ( "should be able to revert when calling with an env-obj" , function ( ) {
80
+ var newObj = { hello : "hello" } ;
81
+
82
+ expect ( moduleFake . getValue ( ) ) . to . be ( 0 ) ;
83
+ expect ( moduleFake . getReference ( ) ) . to . eql ( { } ) ;
84
+
85
+ var undo = moduleFake . __set__ ( {
86
+ myValue : 2 ,
87
+ myReference : newObj
88
+ } ) ;
89
+
90
+ expect ( moduleFake . getValue ( ) ) . to . be ( 2 ) ;
91
+ expect ( moduleFake . getReference ( ) ) . to . be ( newObj ) ;
92
+
93
+ undo ( ) ;
94
+
95
+ expect ( moduleFake . getValue ( ) ) . to . be ( 0 ) ;
96
+ expect ( moduleFake . getReference ( ) ) . to . eql ( { } ) ;
74
97
} ) ;
75
98
it ( "should throw a TypeError when passing misfitting params" , function ( ) {
76
99
expect ( function ( ) {
@@ -101,4 +124,4 @@ describe("__set__", function () {
101
124
moduleFake . __set__ ( "someVar" ) ; // misfitting number of params
102
125
} ) . to . throwException ( expectTypeError ) ;
103
126
} ) ;
104
- } ) ;
127
+ } ) ;
0 commit comments