Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Testing with Jest #54491

Closed
uzairali001 opened this issue Aug 24, 2023 · 2 comments
Closed

Docs: Testing with Jest #54491

uzairali001 opened this issue Aug 24, 2023 · 2 comments
Labels
Documentation Related to Next.js' official documentation. locked

Comments

@uzairali001
Copy link
Contributor

What is the improvement or update you wish to see?

Link to documentation
There is a small error in this documentation, In jest.config.mjs file the import needs to include .js extension like this import nextJest from 'next/jest.js' otherwise it shows this error

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\uzair\Downloads\next-test\node_modules\next\jest' imported from C:\Users\uzair\Downloads\next-test\jest.config.mjs
Did you mean to import next-test/node_modules/next/jest.js?
    at new NodeError (node:internal/errors:399:5)
    at finalizeResolution (node:internal/modules/esm/resolve:326:11)
    at moduleResolve (node:internal/modules/esm/resolve:945:10)
    at defaultResolve (node:internal/modules/esm/resolve:1153:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36)

I created the pull request to fix this issue #54107

Here's the fresh nextjs install with default options repo, in which I've only installed jest by following the documentation npm install --save-dev jest jest-environment-jsdom @testing-library/react @testing-library/jest-dom and it's also showing this error.

Is there any context that might help us understand?

I created the pull request to add .js extension while importing jest library which resolves this issue.

Does the docs page already exist? Please link to it.

https://nextjs.org/docs/pages/building-your-application/optimizing/testing#jest-and-react-testing-library

@uzairali001 uzairali001 added the Documentation Related to Next.js' official documentation. label Aug 24, 2023
@balazsorban44
Copy link
Member

Thanks, I think your PR is valid, so I reopened it. See #54107 (comment)

@github-actions
Copy link
Contributor

github-actions bot commented Sep 7, 2023

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Sep 7, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation Related to Next.js' official documentation. locked
Projects
None yet
Development

No branches or pull requests

2 participants