Next.js Discord

Discord Forum

Install Jest on Nextjs 13 App Router

Unanswered
evro posted this in #help-forum
Open in Discord
I'm trying to install jest for app router and I've been unsuccessful. I've tried following the link below but no luck. I'm currently getting this error:
Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.


That said, I've tried following this url, https://jestjs.io/docs/ecmascript-modules#module-mocking-in-esm but receive this error:
 FAIL  __test__/app/page.test.tsx
  ● Test suite failed to run

    Must use import to load ES Module: /Users/evro/non_iCloud_files/Code/web2/optimaflo/frontend/node_modules/jose/dist/browser/index.js


Has anyone successfully installed Jest for the new app router?

https://nextjs.org/docs/architecture/nextjs-compiler#jest

3 Replies

Any help will be greatly appreciated.
Following the issue above, it appears that there's no clear way to implement this yet on nextjs 13 app router.