Skip to content

Commit

Permalink
Click into the textarea to focus it
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Oct 17, 2022
1 parent d9daf50 commit 24b2f4e
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

/**
* WordPress dependencies
Expand Down Expand Up @@ -82,18 +83,23 @@ describe( 'withFocusReturn()', () => {
expect( switchFocusTo ).toHaveFocus();
} );

it( 'should switch focus back when unmounted while having focus', () => {
it( 'should switch focus back when unmounted while having focus', async () => {
const user = userEvent.setup( {
advanceTimers: jest.advanceTimersByTime,
} );

const { container, unmount } = render( <Composite />, {
container: document.body.appendChild(
document.createElement( 'div' )
),
} );

screen
.getByRole( 'textbox', {
// Click inside the textarea to focus it.
await user.click(
screen.getByRole( 'textbox', {
name: 'Textarea',
} )
.focus();
);

// Should return to the activeElement saved with this component.
unmount();
Expand Down

0 comments on commit 24b2f4e

Please sign in to comment.