-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
next@12.1.6 jest failed tests with dynamic imports #36647
Comments
From v12.1.6-canary.9 it's started failing |
I'm also getting this failure with jest 27.4.7. |
Does anyone have a simple but complete reproduction? 🙏 |
It's reproducible with the
export default function () {
return <h1>Hello world!</h1>;
}
...
import dynamic from "next/dynamic"
const Component = dynamic(() => import("../Component"));
export default function Home() {
return (
...
<Component />
)
}
import { render, screen, waitFor } from "@testing-library/react";
import Home from "@/pages/index";
describe("Home", () => {
it("renders a heading", async () => {
render(<Home />);
// this will fail
expect(
screen.getByRole("heading", { name: "Hello world!" })
).toBeInTheDocument();
// this will not fail
await waitFor(() => {
expect(
screen.getByRole("heading", { name: "Hello world!" })
).toBeInTheDocument();
});
});
}) As a side note it seems like jest in the default example can't import css modules so I commented them out. |
Looking at the release it might be related to the changes in #36464 |
This applies also for snapshot tests. Sadly, the |
This issue has been automatically closed because it received no activity for a month and had no reproduction to investigate. If you think this was closed by accident, please leave a comment. If you are running into a similar issue, please open a new issue with a reproduction. Thank you. |
@OlesZadorozhnyy can you change the description of this issue to include a reproduction? I've written a reproduction in a comment. |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
All components that have dynamic imports started failing in tests. Jest doesn't see it synchronously. Only with Jest API method
waitFor
it works.Expected Behavior
Tests with components that have dynamic imports works as before (v.12.1.5)
To Reproduce
The text was updated successfully, but these errors were encountered: