Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AlignmentMatrixControl: replace act() with userEvent #53703

Merged
merged 1 commit into from Aug 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
import { act, render, screen, within } from '@testing-library/react';
import { render, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

/**
* Internal dependencies
Expand All @@ -27,6 +28,7 @@ describe( 'AlignmentMatrixControl', () => {

describe( 'Change value', () => {
const alignments = [ 'center left', 'center center', 'bottom center' ];
const user = userEvent.setup();

it.each( alignments )(
'should change value on %s cell click',
Expand All @@ -37,7 +39,9 @@ describe( 'AlignmentMatrixControl', () => {
<AlignmentMatrixControl value="center" onChange={ spy } />
);

await act( () => getCell( alignment ).focus() );
await user.click( getCell( alignment ) );

expect( getCell( alignment ) ).toHaveFocus();
Copy link
Member

Choose a reason for hiding this comment

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

Replacing a .focus() with a .click() makes the intention a bit less clear, but the "have focus" assertion definitely helps clarify it, so thanks for adding that assertion 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for sharing! It's helpful to know it was a useful addition.


expect( spy ).toHaveBeenCalledWith( alignment );
}
Expand Down