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: stop awaiting act() #7152

Merged
merged 2 commits into from
May 22, 2024
Merged

test: stop awaiting act() #7152

merged 2 commits into from
May 22, 2024

Conversation

pjonsson
Copy link
Contributor

What this PR does

This fixes the warning:

Do not await the result of calling act(...) with sync logic, it is not a Promise.

Test me

Tests only update.

Checklist

  • There are unit tests to verify my changes are correct or unit tests aren't applicable (if so, write quick reason why unit tests don't exist)
  • I've updated relevant documentation in doc/.
  • I've updated CHANGES.md with what I changed.
  • I've provided instructions in the PR description on how to test this PR.

Comment on lines 89 to 92
// FIXME: the await triggers the warning
// "Do not await the result of calling act(...) with sync logic, it is not a Promise."
// but removing the await makes the test for describeParameters fail.
await act(() => {
rendered = render({
item,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Luckily in this case the ItemSearchTool component accepts an afterLoad callback, so we can use it to wait on.
Something like this should work:

    let renderPromise: Promise<void> | undefined;
    act(() => {
      renderPromise = new Promise((resolve) => render({
        item,
        itemSearchProvider,
        viewState,
        afterLoad: resolve
      }));
    });
    await renderPromise;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a commit with the suggestion and the tests now pass, thanks!

@na9da
Copy link
Collaborator

na9da commented May 21, 2024

@pjonsson - thanks as always for your PRs, I have added a suggestion to fix the ItemSearchProviderSpec.

This fixes the warning:

Do not await the result of calling act(...) with sync logic, it is not a Promise.
Use the suggested fix from the code review
to remove the final await on act.
@pjonsson
Copy link
Contributor Author

As a beginner it's hard to know where to look because of all the warnings (and easy to miss something essential). I'm guessing this PR falls somewhere between trivial and requires testing/effort, but it would be nice if the trivial stuff like #7134, #7136, and TerriaJS/terriajs-server#158 could get merged.

Copy link
Collaborator

@na9da na9da left a comment

Choose a reason for hiding this comment

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

Looks good, merging.

@na9da na9da merged commit e6b2cca into TerriaJS:main May 22, 2024
6 checks passed
@pjonsson pjonsson deleted the fix-await-warnings branch May 22, 2024 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants