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

Warnings of test not wrapped in act since 9.3.2 #1275

Closed
joaopedrodcf opened this issue Nov 7, 2023 · 10 comments
Closed

Warnings of test not wrapped in act since 9.3.2 #1275

joaopedrodcf opened this issue Nov 7, 2023 · 10 comments

Comments

@joaopedrodcf
Copy link

  • @testing-library/dom version: 9.3.2 or greater
  • Testing Framework and version: jest 29.7.0
  • DOM Environment: jest-environment-jsdom 29.7.0

Relevant code or config:

    it('...' () => {
        const user = userEvent.setup();
        render(<ResetPasswordForm />);

        const newPasswordInput = screen.getByLabelText(...);

        // The test will start warning here as can be seen in the screenshot below
        await user.type(newPasswordInput, ...);

What you did:

Upgraded from 9.3.1 to 9.3.2

What happened:

The warnings started appearing all over the place

Reproduction:

Problem description:

Upgrading from "@testing-library/dom": "9.3.1", to `"@testing-library/dom": "9.3.2" will start showing warnings in almost every test.
All the warnings are related with not wrapping in act.
image

Suggested solution:

I don't have suggested solution as I never checked the codebase of dom testing library, probably something changed from version 9.3.1 to 9.3.2

Copy link

github-actions bot commented Nov 7, 2023

Uh oh! @joaopedrodcf, the image you shared is missing helpful alt text. Check your issue body.

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

@MatanBobi
Copy link
Member

Hi @joaopedrodcf.
The act error is from React Testing Library, is there any specific reason why you have DTL installed explicitly?
We have this issue that suggests it might be related to multiple DTL versions installed: testing-library/react-testing-library#1216

@joaopedrodcf
Copy link
Author

Wow, that was really quick @MatanBobi :D

Yeah, it was getting duplicated like this! After removing it, it works again 🥇

I think I saw it in next documentation but tried to look again but can't find it anymore maybe they updated their docs 😆

Gonna close the issue

@joaopedrodcf
Copy link
Author

joaopedrodcf commented Nov 7, 2023

Actually found the reason @MatanBobi why I add installed the @testing-library/dom.

In the docs of user-event they say that we need to install it:
https://testing-library.com/docs/ecosystem-user-event/

image

Even yarn will say that a peer dep is not met if we don't install it

image

Copy link

github-actions bot commented Nov 7, 2023

Uh oh! @joaopedrodcf, the image you shared is missing helpful alt text. Check #1275 (comment).

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

1 similar comment
Copy link

github-actions bot commented Nov 7, 2023

Uh oh! @joaopedrodcf, the image you shared is missing helpful alt text. Check #1275 (comment).

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

@joaopedrodcf
Copy link
Author

Just to add more information for the issue:

image image

It can be seen in the yarn.lock the 9.0.0 was resolved to 9.3.1 and then 9.3.3 was the one I installed manually

So the solution for me was to basically relly in "resolutions" ( overrides in npm ) to force the same version and not having a warning in doing yarn because of a missing peer dependency

// package.json

{
    "devDependencies": {
        "@testing-library/dom": "9.3.3",
        "@testing-library/react": "14.0.0",
        "@testing-library/user-event": "14.5.1",
    },
    "resolutions": {
        "@testing-library/dom": "9.3.3"
    }
}

Copy link

github-actions bot commented Nov 7, 2023

Uh oh! @joaopedrodcf, the image you shared is missing helpful alt text. Check #1275 (comment).

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

@MatanBobi
Copy link
Member

MatanBobi commented Nov 7, 2023

We have an open PR to remove that: testing-library/testing-library-docs#1329
This was relevant back when peerDependencies weren't downloaded in case they weren't installed already.
You can safely remove @testing-library/dom from your devDependencies.
I'm resolving this one as it's a duplicate of the open issue in RTL (testing-library/react-testing-library#1216) and for the specific concern you've raised, we already have an open PR in the docs.
Thanks!

@joaopedrodcf
Copy link
Author

Thank you so much 🙏

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

No branches or pull requests

2 participants