Next.js Discord

Discord Forum

After updating to 13.5.2 tests fail because of router not mounted

Unanswered
Miniature Bull Terrier posted this in #help-forum
Open in Discord
Avatar
Miniature Bull TerrierOP
Hi guys,

I updated our project to the new version. Which works when I run dev. But my unit tests now fail. I get an error that router is not mounted. But it is mocked and it have worked prior the update. We test with jest. We mocked the router by adding the next line of code in the setup file.

jest.mock("next/router", () => ({
useRouter() {
return {
push: jest.fn(),
route: "/",
pathname: "",
asPath: "",
locale: "nl-NL",
};
},
}));

"NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted"

Anyone a suggestion? Thnx!

5 Replies

Avatar
SupremeDeity
Is that useRouter() being imported from the correct place?
Which is next/router?
Avatar
Miniature Bull TerrierOP
thats correct, the router in the components are imported from the correct place, so the page router "next/router"
Avatar
SupremeDeity
Im tempted to say this might be a bug then
Recheck the recent PRs to see if something changed there else open a issue on GitHub