Testing with Jest
leobelen opened this issue · 1 comments
leobelen commented
Whenever testing components tax with Jest, it fails because it cannot use the useRouter hook... is there a proper way to mock it or configure the package properly with jest?
So far, assuming that TestComponent does contain only a Component that shows a translated text, what should I do
import { render } from '@testing-library/react';
import TestComponent from '.';
describe('<TestComponent />', () => {
it('should render the heading', () => {
const { container } = render(<TestComponent />);
expect(container).toBeDefined();
});
});
As of now it fails with the following error:
Error: Uncaught [Error: NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted]
Thanks in advance.
martinkr commented
Thank you for your contribution.
I can not reproduce this error. Please try the latest version.