-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
NextJS 10 breaks tests by throwing warnings for components using next/link #20048
Comments
I'm getting the same. |
i just spent hours trying to figure out what the heck i was doing wrong. having the same problem. |
React complains if you attempt to make changes either outside of `act` or after the component has unmounted. In tests with this setup, the idle callback is scheduled and run later, but the component has already been unmounted. This ensures unmounted components don't run their idle callback. Fixes vercel#20048.
PR to resolve: #20169. I need to test it fully myself but would appreciate if anyone experiencing this issue could give it a try. |
@mAAdhaTTah When I install NextJS from your PR, it fails to install "next/babel", and then nothing works. Any idea why? I am trying to test against your PR to help move it forward. |
@thanos-diacakis-grandrounds I tested it by cloning the repo, running the build, and then copying the dist folder into my project's |
Thanks for the steps. I have performed those, and I can confirm that it un-breaks all of our tests. In case anyone else wants to follow this and needs more details:
|
React complains if you attempt to make changes either outside of `act` or after the component has unmounted. In tests with this setup, the idle callback is scheduled and run later, but the component has already been unmounted. This ensures unmounted components don't run their idle callback. Fixes vercel#20048.
React complains if you attempt to make changes either outside of `act` or after the component has unmounted. In tests with this setup, the idle callback is scheduled and run later, but the component has already been unmounted. This ensures unmounted components don't run their idle callback. Fixes vercel#20048.
React complains if you attempt to make changes either outside of `act` or after the component has unmounted. In tests with this setup, the idle callback is scheduled and run later, but the component has already been unmounted. This ensures unmounted components don't run their idle callback. Fixes vercel#20048.
I experienced this too. And since a fix looks to be implemented, I didn't want to really change anything. Fortunately we can temporarily squash the errors. Simply place the below at the top of the test file spitting the error (and remove once you've updated Next.js): // this is just a little hack to silence a warning that we'll get until we
// upgrade to 16.9. See also: https://github.com/facebook/react/pull/14853
import "@testing-library/react";
const originalError = console.error;
beforeAll(() => {
console.error = (...args) => {
if (/Warning.*not wrapped in act/.test(args[0])) {
return;
}
originalError.call(console, ...args);
};
});
afterAll(() => {
console.error = originalError;
}); |
React complains if you attempt to make changes either outside of `act` or after the component has unmounted. In tests with this setup, the idle callback is scheduled and run later, but the component has already been unmounted. This ensures unmounted components don't run their idle callback. Fixes #20048.
I'm still getting errors for simply rendering a Link. Instead of supressing the error, I prefer to just mock the Link component: // put this in your setupTests.js or some other file that runs before your tests
jest.mock('next/link', () => ({
__esModule: true,
default: ({ children, href }) => (
<children.type {...children.props} href={href} />
)
})); |
Like @gsantiago I still experience this @10.05, @Timer. Do you need a repro? |
Getting this again in next@10.2.3 with components in tests that consume dynamic components. I'll open an issue with a reproduction. |
Thanks @gsantiago. Ran into this same issue when using // test/mocks/Link.js
export default ({ children, href }) => (
<children.type {...children.props} href={href} />
); and mocked across the test suite using // jest.config.js
module.exports = {
moduleNameMapper: {
'next/link': require.resolve('./test/mocks/Link.js'),
}
} |
Also happening to me. To give more context, this is happening to me given the following package versions: "next": "^11.0.1",
"react": "^17.0.2",
"react-dom": "^17.0.2", I've ended up mocking the |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
Minimal code to replicate: https://github.com/thanos-diacakis-grandrounds/nextjs-10-link-test-errors
We have a simple component includes a next/link. We have tests that will render the component, and assert various things (assertions omitted in the sample code). This works fine in NextJS 9.5.6. When upgrading to NextJS 10, these tests start throwing the following two warnings:
To Reproduce
Expected behavior
We expected to see the same behavior as NextJS 9.x - no warnings.
Screenshots
System information
Additional context
If there is a single test, it seems to pass with no warnings. Once you add more tests, it seems to fail, even if the additional tests do nothing at all.
Removing the resolves the issue.
Tried turning off prefetching, making the act() function async/await, assuming some kind of state change is happening behind the scenes with no luck.
The text was updated successfully, but these errors were encountered: