Skip to content

Commit

Permalink
Add explanatory comments about await act()
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Oct 25, 2022
1 parent fd4cc97 commit 6c4349a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/components/src/border-control/test/index.js
Expand Up @@ -39,19 +39,26 @@ const toggleLabelRegex = /Border color( and style)* picker/;

const renderBorderControl = async ( props ) => {
const view = render( <BorderControl { ...props } /> );
// When the `Popover` component is rendered or updated, the `useFloating`
// hook from the `floating-ui` package will schedule a state update in a
// promise handler. We need to wait for this promise handler to execute
// before checking results. That's what this async `act()` call achieves.
// See also: https://floating-ui.com/docs/react-dom#testing
await act( () => Promise.resolve() );
return view;
};

const rerenderBorderControl = async ( rerender, props ) => {
const view = rerender( <BorderControl { ...props } /> );
// Same reason to `act()` as in `renderBorderControl` above.
await act( () => Promise.resolve() );
return view;
};

const openPopover = async () => {
const toggleButton = screen.getByLabelText( toggleLabelRegex );
fireEvent.click( toggleButton );
// Same reason to `act()` as in `renderBorderControl` above.
await act( () => Promise.resolve() );
};

Expand Down

0 comments on commit 6c4349a

Please sign in to comment.