next-international
next-international copied to clipboard
vitest on app router can't work
Describe the bug I used the package to run vitest on the app router, but an error occurred.
FAIL app/[locale]/sample.test.tsx > Example test > just an example
Error: NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted
❯ useRouter node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/node_modules/next/src/client/router.ts:135:11
❯ I18nProvider node_modules/.pnpm/[email protected]/node_modules/next-international/dist/index.js:131:89
❯ renderWithHooks node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:16305:18
❯ mountIndeterminateComponent node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:20074:13
❯ beginWork node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:21587:16
❯ beginWork$1 node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27426:14
❯ performUnitOfWork node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26560:12
❯ workLoopSync node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26466:5
❯ renderRootSync node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26434:7
❯ recoverFromConcurrentError node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25850:20
To Reproduce
- https://github.com/takumiya081/next-international-vitest-app-router
-
pnpm test
About (please complete the following information):
- next-international 1.1.4
- Next.js latest
- vitest 1.0.4
This has nothing to do with vitest or the package. The error is on next router
@takumiya081 You could use next-router-mock
.
@takumiya081 You could use
next-router-mock
.
Were you able to solve this issue with next-router-mock
? I've tried but no luck...
@takumiya081 You could use
next-router-mock
.Were you able to solve this issue with
next-router-mock
? I've tried but no luck...
I just followed the documentation, right now I don't remember it pretty well.
I encountered the same problem