diff --git a/packages/data/src/components/use-select/test/index.js b/packages/data/src/components/use-select/test/index.js index 6dccfd74b741fc..4b7babcedeaac7 100644 --- a/packages/data/src/components/use-select/test/index.js +++ b/packages/data/src/components/use-select/test/index.js @@ -1146,4 +1146,38 @@ describe( 'useSelect', () => { expect( screen.getByRole( 'status' ) ).toHaveTextContent( '10' ); } ); } ); + + describe( 'static store selection mode', () => { + it( 'can read the current value from store', () => { + registry.registerStore( 'testStore', { + reducer: ( s = 0, a ) => ( a.type === 'INC' ? s + 1 : s ), + actions: { inc: () => ( { type: 'INC' } ) }, + selectors: { get: ( s ) => s }, + } ); + + const record = jest.fn(); + + function TestComponent() { + const { get } = useSelect( 'testStore' ); + return ( + + ); + } + + render( + + + + ); + + fireEvent.click( screen.getByRole( 'button' ) ); + expect( record ).toHaveBeenLastCalledWith( 0 ); + + // no need to act() as the component doesn't react to the updates + registry.dispatch( 'testStore' ).inc(); + + fireEvent.click( screen.getByRole( 'button' ) ); + expect( record ).toHaveBeenLastCalledWith( 1 ); + } ); + } ); } );