@@ -37,6 +37,17 @@ describe('state handler', () => {
3737 } )
3838 } )
3939
40+ it ( 'init_variable does not update state if variable is defined' , ( ) => {
41+ const state_handler = create_state_handler ( )
42+ state_handler . init_variable ( 'bar' , false )
43+ state_handler . init_variable ( 'pi' , 3.14 )
44+ state_handler . init_variable ( 'pi' , - 3.14 )
45+ state_handler . get_state ( ) . should . deepEqual ( {
46+ 'bar' : false ,
47+ 'pi' : 3.14
48+ } )
49+ } )
50+
4051 it ( 'set_variable should update state' , ( ) => {
4152 const state_handler = create_state_handler ( )
4253 state_handler . set_variable ( 'foo' , 42 )
@@ -90,6 +101,15 @@ describe('state handler', () => {
90101 my_callback . should . be . calledOnce ( )
91102 } )
92103
104+ it ( 'no state change if init_variable is called twice on the same variable' , ( ) => {
105+ const my_callback = sinon . spy ( function ( ) { state_handler . subscribe ( my_callback ) } )
106+ const state_handler = create_state_handler ( )
107+ state_handler . subscribe ( my_callback )
108+ state_handler . init_variable ( 'foo' , 42 )
109+ state_handler . init_variable ( 'foo' , 42 )
110+ my_callback . should . be . calledOnce ( )
111+ } )
112+
93113 it ( 'callback should be called again with re-subscribe' , ( ) => {
94114 const my_callback = sinon . spy ( function ( ) { state_handler . subscribe ( my_callback ) } )
95115 const state_handler = create_state_handler ( )
0 commit comments