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

[test] Add missing async #44028

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/mui-base/src/Menu/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('<Menu />', () => {
const item2 = getByTestId('item-2');
const item3 = getByTestId('item-3');

await act(() => {
await act(async () => {
item1.focus();
});

Expand Down Expand Up @@ -234,7 +234,7 @@ describe('<Menu />', () => {
const item1 = getByTestId('item-1');
const item3 = getByTestId('item-3');

await act(() => {
await act(async () => {
item1.focus();
});

Expand All @@ -260,7 +260,7 @@ describe('<Menu />', () => {
const item1 = getByTestId('item-1');
const item2 = getByTestId('item-2');

await act(() => {
await act(async () => {
Copy link

@potapovDim potapovDim Oct 7, 2024

Choose a reason for hiding this comment

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

why async is needed here if
items[0].focus(); does not have await ?
it make sense to have it as
await act(async () => items[0].focus());
or

await act(async () => {
    await items[0].focus();
})

Copy link
Member

@Janpot Janpot Oct 7, 2024

Choose a reason for hiding this comment

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

From https://react.dev/reference/react/act#await-act-async-actfn

We recommend using act with await and an async function. Although the sync version works in many cases, it doesn’t work in all cases and due to the way React schedules updates internally, it’s difficult to predict when you can use the sync version.

We will deprecate and remove the sync version in the future.

or, the async is there because it changes the behavior of act. I understand it looks a bit strange to not await anything. but it's still nicer than doing

await act(() => {
  items[0].focus();
  return Promise.resolve();
})

No need to await items[0].focus(). It doesn't return a promise.

item1.focus();
});

Expand Down Expand Up @@ -293,7 +293,7 @@ describe('<Menu />', () => {

const items = getAllByRole('menuitem');

await act(() => {
await act(async () => {
items[0].focus();
});

Expand Down Expand Up @@ -326,7 +326,7 @@ describe('<Menu />', () => {

const items = getAllByRole('menuitem');

await act(() => {
await act(async () => {
items[0].focus();
});

Expand Down Expand Up @@ -357,7 +357,7 @@ describe('<Menu />', () => {

const items = getAllByRole('menuitem');

await act(() => {
await act(async () => {
items[0].focus();
});

Expand Down Expand Up @@ -399,7 +399,7 @@ describe('<Menu />', () => {

const items = getAllByRole('menuitem');

await act(() => {
await act(async () => {
items[0].focus();
});

Expand Down Expand Up @@ -436,7 +436,7 @@ describe('<Menu />', () => {

const items = getAllByRole('menuitem');

await act(() => {
await act(async () => {
items[0].focus();
});

Expand Down Expand Up @@ -471,7 +471,7 @@ describe('<Menu />', () => {

const items = getAllByRole('menuitem');

await act(() => {
await act(async () => {
items[0].focus();
});

Expand Down Expand Up @@ -666,7 +666,7 @@ describe('<Menu />', () => {
);

const menuItems = getAllByRole('menuitem');
await act(() => {
await act(async () => {
menuItems[0].focus();
});

Expand Down