@@ -5,14 +5,18 @@ import { Model } from '../../src'
55
66describe ( 'useStore' , ( ) => {
77 test ( 'create by single model definition' , async ( ) => {
8- let state : any
9- let actions : any
8+ let state : any , nextState : any
9+ let actions : any , nextActions : any
1010 let count = 0
11+ let nextCount = 0
1112 const Home = Model ( NextCounter )
12- const { useStore, subscribe, unsubscribe } = Model ( { Home } )
13+ const { useStore, subscribe, unsubscribe } = Model ( { Home, NextCounter } )
1314 renderHook ( ( ) => {
1415 ; [ state , actions ] = useStore ( 'Home' )
16+ ; [ nextState , nextActions ] = useStore ( 'NextCounter' )
1517 } )
18+
19+ // Home
1620 expect ( state ) . toEqual ( { count : 0 } )
1721 await actions . increment ( 3 )
1822 expect ( state ) . toEqual ( { count : 3 } )
@@ -26,5 +30,20 @@ describe('useStore', () => {
2630 await actions . increment ( 3 )
2731 expect ( state . count ) . toBe ( 10 )
2832 expect ( count ) . toBe ( 1 )
33+
34+ // NextCounter
35+ expect ( nextState ) . toEqual ( { count : 0 } )
36+ await nextActions . increment ( 3 )
37+ expect ( nextState ) . toEqual ( { count : 3 } )
38+ // test subscribe
39+ subscribe ( 'NextCounter' , 'increment' , ( ) => ( nextCount += 1 ) )
40+ await nextActions . increment ( 4 )
41+ expect ( nextCount ) . toBe ( 1 )
42+ expect ( nextState . count ) . toBe ( 7 )
43+ // test unsubscribe
44+ unsubscribe ( 'NextCounter' , 'increment' )
45+ await nextActions . increment ( 3 )
46+ expect ( nextState . count ) . toBe ( 10 )
47+ expect ( nextCount ) . toBe ( 1 )
2948 } )
3049} )
0 commit comments