File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -175,6 +175,26 @@ describe('useSharedState', () => {
175175 // Get value after clear (should be initial value because createSharedState re-initializes it)
176176 expect ( sharedStatesApi . get ( sharedCounter ) ) . toBe ( 100 ) ;
177177 } ) ;
178+
179+ it ( 'should be able to subscribe to state changes from api' , ( ) => {
180+ const sharedCounter = createSharedState ( 100 ) ;
181+
182+ const subscribeCallback = vi . fn ( ) ;
183+
184+ act ( ( ) => {
185+ sharedStatesApi . subscribe ( sharedCounter , ( ) => {
186+ subscribeCallback ( ) ;
187+ expect ( sharedStatesApi . get ( sharedCounter ) ) . toBe ( 200 ) ;
188+ } ) ;
189+ } ) ;
190+
191+ // Update the value
192+ act ( ( ) => {
193+ sharedStatesApi . set ( sharedCounter , 200 ) ;
194+ } ) ;
195+
196+ expect ( subscribeCallback ) . toHaveBeenCalledTimes ( 1 ) ;
197+ } ) ;
178198} ) ;
179199
180200describe ( 'useSharedFunction' , ( ) => {
You can’t perform that action at this time.
0 commit comments