next-international icon indicating copy to clipboard operation
next-international copied to clipboard

vitest on app router can't work

Open takumiya081 opened this issue 1 year ago • 6 comments

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

  1. https://github.com/takumiya081/next-international-vitest-app-router
  2. pnpm test

About (please complete the following information):

  • next-international 1.1.4
  • Next.js latest
  • vitest 1.0.4

takumiya081 avatar Jan 01 '24 11:01 takumiya081

This has nothing to do with vitest or the package. The error is on next router

kyeshmz avatar Jan 22 '24 07:01 kyeshmz

@takumiya081 You could use next-router-mock.

SalahAdDin avatar Feb 01 '24 15:02 SalahAdDin

@takumiya081 You could use next-router-mock.

Were you able to solve this issue with next-router-mock ? I've tried but no luck...

Luke-Gurgel avatar May 09 '24 18:05 Luke-Gurgel

@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.

SalahAdDin avatar May 09 '24 18:05 SalahAdDin

I encountered the same problem

Deer404 avatar May 13 '24 08:05 Deer404