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

Incomplete module path in with-jest example #60239

Closed
1 task done
vondersam opened this issue Jan 4, 2024 · 2 comments
Closed
1 task done

Incomplete module path in with-jest example #60239

vondersam opened this issue Jan 4, 2024 · 2 comments
Labels
examples Issue/PR related to examples locked

Comments

@vondersam
Copy link

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 19.6.0: Tue Jun 21 21:18:39 PDT 2022; root:xnu-6153.141.66~1/RELEASE_X86_64
Binaries:
  Node: 20.9.0
  npm: 10.1.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.0.4
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which example does this report relate to?

with-jest

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

When running the tests with the example out of the box, two tests fail.

 FAIL  __tests__/index.test.tsx
   Test suite failed to run

    Cannot find module 'pages/index' from '__tests__/index.test.tsx'

       7 | describe('Home', () => {
       8 |   it('renders a heading', () => {
    >  9 |     render(<Home />)
         |                                                       ^
      10 |
      11 |     const heading = screen.getByRole('heading', {
      12 |       name: /welcome to next\.js!/i,

      at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:427:11)
      at Object.<anonymous> (__tests__/index.test.tsx:9:55)

And

 FAIL  __tests__/snapshot.tsx
   Test suite failed to run

    Cannot find module 'pages/index' from '__tests__/snapshot.tsx'

       7 | it('renders homepage unchanged', () => {
       8 |   const { container } = render(<Home />)
    >  9 |   expect(container).toMatchSnapshot()
         |                                                ^
      10 | })
      11 |

      at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:427:11)
      at Object.<anonymous> (__tests__/snapshot.tsx:9:55)

I we implement these changes in these files, the tests pass:
/__tests__/index.test.tsx

- import Home from '@/pages/index';
+ import Home from '@/pages/home/index';

`tests/snapshot.tsx``

- import Home from '@/pages/index';
+ import Home from '@/pages/home/index'

### Expected Behavior

Tests pass when running them after creating the project.

### To Reproduce

```console
npx create-next-app --example with-jest test
npm run test:ci
@vondersam vondersam added the examples Issue/PR related to examples label Jan 4, 2024
@samcx
Copy link
Member

samcx commented Jan 6, 2024

:fixed:#60332

@samcx samcx closed this as completed Jan 6, 2024
Copy link
Contributor

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 locked as resolved and limited conversation to collaborators Jan 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
examples Issue/PR related to examples locked
Projects
None yet
Development

No branches or pull requests

2 participants