Skip to content

Commit

Permalink
useSelect: add unit tests for static select mode (#46606)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Dec 16, 2022
1 parent 9ea80f6 commit cd8451d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/data/src/components/use-select/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<button onClick={ () => record( get() ) }>record</button>
);
}

render(
<RegistryProvider value={ registry }>
<TestComponent />
</RegistryProvider>
);

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 );
} );
} );
} );

1 comment on commit cd8451d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3712976797
📝 Reported issues:

Please sign in to comment.