-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Closed
Description
Question about Next.js
I'm want to make sure my component renders correctly with useRouter hook (actually I'm trying to understand how new dynamic routing works), so I have code:
import React from 'react';
import { NextPage } from 'next';
import { useRouter } from 'next/router';
const UserInfo : NextPage = () => {
const router = useRouter();
const { query } = router;
return <div>Hello {query.user}</div>;
};
export default UserInfo;And what I'm trying is:
// test
import { render, cleanup, waitForElement } from '@testing-library/react';
import UserInfo from './$user';
// somehow mock useRouter for $user component!!!
afterEach(cleanup);
it('Should render correctly on route: /users/nikita', async () => {
const { getByText } = render(<UserInfo />);
await waitForElement(() => getByText(/Hello nikita!/i));
});But I get an error TypeError: Cannot read property 'query' of null which points on const router = useRouter(); line.
P. S. I know dynamic routing is available on canary verions just for now and might change, but I get a problem with router, not with WIP feature (am I?).
mateja176, mulyoved, AntonioRedondo, RaziRaiyan, EvHaus and 2 more
Metadata
Metadata
Assignees
Labels
No labels