Closed elite0226 closed 3 years ago
I had a similar issue, after upgrading to Jest v27 I suddenly got invalid hook usage errors.
In my case the problem turned out to be my usage of jest.isolateModules
, I was requiring the component in each test. Example:
it('should display the menu item', () => {
jest.isolateModules(() => {
module = require('../../../../components/layout/header/X'); // this line is problematic
const component = render(
<module.X />,
{}
);
expect(component.queryByText('Home')).toBeTruthy();
});
});
I refactored the tests and mocks to require the component in beforeEach
and things started working again.
What version of Next.js are you using?
10.1.3
What version of Node.js are you using?
14.7.0
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
Vercel
Describe the Bug
Recently, I've upgraded all dependencies to the latest versions including Next.js and React.
Once I upgraded, some pages run into
Invalid Hook call
error. Similar issues were reported on both React and Next.js repos but none of them works for me.So I ended up with downgrading the React version to 16.14.0 and it's working well but I'd like to use the features of React v17 with Next.js v10.
Expected Behavior
No errors with the latest versions of dependencies.
To Reproduce
Here are the dependencies I have used:
and here is the screenshot of an error: