Skip to content

Commit

Permalink
Refactor to use userEvent instead of fireEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Dec 16, 2022
1 parent 1d21a3e commit f97baf6
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/data/src/components/use-select/test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
import { act, render, fireEvent, screen } from '@testing-library/react';
import { act, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

/**
* WordPress dependencies
Expand Down Expand Up @@ -435,7 +436,9 @@ describe( 'useSelect', () => {
);
} );

it( 'captures state changes scheduled between render and effect', () => {
it( 'captures state changes scheduled between render and effect', async () => {
const user = userEvent.setup();

registry.registerStore( 'store-1', counterStore );

class ChildComponent extends Component {
Expand Down Expand Up @@ -484,7 +487,7 @@ describe( 'useSelect', () => {
</RegistryProvider>
);

fireEvent.click( screen.getByText( 'triggerChildDispatch' ) );
await user.click( screen.getByText( 'triggerChildDispatch' ) );

expect( selectCount1AndDep ).toHaveBeenCalledTimes( 3 );
expect( screen.getByRole( 'status' ) ).toHaveTextContent(
Expand Down Expand Up @@ -1148,7 +1151,9 @@ describe( 'useSelect', () => {
} );

describe( 'static store selection mode', () => {
it( 'can read the current value from store', () => {
it( 'can read the current value from store', async () => {
const user = userEvent.setup();

registry.registerStore( 'testStore', {
reducer: ( s = 0, a ) => ( a.type === 'INC' ? s + 1 : s ),
actions: { inc: () => ( { type: 'INC' } ) },
Expand All @@ -1170,13 +1175,13 @@ describe( 'useSelect', () => {
</RegistryProvider>
);

fireEvent.click( screen.getByRole( 'button' ) );
await user.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' ) );
await user.click( screen.getByRole( 'button' ) );
expect( record ).toHaveBeenLastCalledWith( 1 );
} );
} );
Expand Down

1 comment on commit f97baf6

@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/3712177572
📝 Reported issues:

Please sign in to comment.