Skip to content

Commit

Permalink
fireEvent -> user-event
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Dec 20, 2022
1 parent 4c2cdfd commit 26ab8d0
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/components/src/panel/test/body.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
import { render, fireEvent, screen } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

/**
* Internal dependencies
Expand Down Expand Up @@ -113,7 +114,11 @@ describe( 'PanelBody', () => {
expect( panelContent ).toBeVisible();
} );

it( 'should toggle when clicking header', () => {
it( 'should toggle when clicking header', async () => {
const user = userEvent.setup( {
advanceTimers: jest.advanceTimersByTime,
} );

render(
<PanelBody title="Panel" initialOpen={ false }>
<div data-testid="inner-content">Content</div>
Expand All @@ -125,20 +130,23 @@ describe( 'PanelBody', () => {

expect( panelContent ).not.toBeInTheDocument();

fireEvent.click( panelToggle );
await user.click( panelToggle );

panelContent = screen.getByTestId( 'inner-content' );

expect( panelContent ).toBeVisible();

fireEvent.click( panelToggle );
await user.click( panelToggle );

panelContent = screen.queryByTestId( 'inner-content' );

expect( panelContent ).not.toBeInTheDocument();
} );

it( 'should pass button props to panel title', () => {
it( 'should pass button props to panel title', async () => {
const user = userEvent.setup( {
advanceTimers: jest.advanceTimersByTime,
} );
const mock = jest.fn();

render(
Expand All @@ -147,7 +155,7 @@ describe( 'PanelBody', () => {
</PanelBody>
);

fireEvent.click( screen.getByRole( 'button', { name: 'Panel' } ) );
await user.click( screen.getByRole( 'button', { name: 'Panel' } ) );

expect( mock ).toHaveBeenCalled();
} );
Expand Down

1 comment on commit 26ab8d0

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

Please sign in to comment.