@@ -188,6 +188,39 @@ describe('Basic Example - Basic Usage', () => {
188188 expect ( states ) . toHaveLength ( 2 ) ;
189189 } ) ;
190190
191+ test ( 'supports destructured subscribe and getState bindings' , ( ) => {
192+ const capturedStates : AppState [ ] = [ ] ;
193+ const capturedPositions : number [ ] = [ ] ;
194+
195+ const { subscribe, getState } = travels ;
196+
197+ // check function auto bind travel
198+ const unsubscribe = subscribe . call ( { } , ( state , _patches , position ) => {
199+ capturedStates . push ( state ) ;
200+ capturedPositions . push ( position ) ;
201+ } ) ;
202+
203+ travels . setState ( ( draft ) => {
204+ draft . count = 1 ;
205+ } ) ;
206+
207+ expect ( capturedStates ) . toHaveLength ( 1 ) ;
208+ expect ( capturedStates [ 0 ] ) . toEqual ( { count : 1 , text : 'Hello' } ) ;
209+ expect ( capturedPositions ) . toEqual ( [ 1 ] ) ;
210+ // check function auto bind travel
211+ expect ( getState . call ( { } , ) ) . toEqual ( { count : 1 , text : 'Hello' } ) ;
212+
213+ unsubscribe ( ) ;
214+
215+ travels . setState ( ( draft ) => {
216+ draft . count = 2 ;
217+ } ) ;
218+
219+ expect ( capturedStates ) . toHaveLength ( 1 ) ;
220+ expect ( capturedPositions ) . toEqual ( [ 1 ] ) ;
221+ expect ( getState ( ) ) . toEqual ( { count : 2 , text : 'Hello' } ) ;
222+ } ) ;
223+
191224 test ( 'should check canBack and canForward correctly' , ( ) => {
192225 expect ( travels . canBack ( ) ) . toBe ( false ) ;
193226 expect ( travels . canForward ( ) ) . toBe ( false ) ;
@@ -205,4 +238,3 @@ describe('Basic Example - Basic Usage', () => {
205238 expect ( travels . canForward ( ) ) . toBe ( true ) ;
206239 } ) ;
207240} ) ;
208-
0 commit comments