@@ -69,8 +69,31 @@ describe("__set__", function () {
6969 expect ( moduleFake . getValue ( ) ) . to . be ( 2 ) ;
7070 expect ( moduleFake . getReference ( ) ) . to . be ( newObj ) ;
7171 } ) ;
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 ( { } ) ;
7497 } ) ;
7598 it ( "should throw a TypeError when passing misfitting params" , function ( ) {
7699 expect ( function ( ) {
@@ -101,4 +124,4 @@ describe("__set__", function () {
101124 moduleFake . __set__ ( "someVar" ) ; // misfitting number of params
102125 } ) . to . throwException ( expectTypeError ) ;
103126 } ) ;
104- } ) ;
127+ } ) ;
0 commit comments