vercel / vercel/next.js

Jest Manual mocks stopped working in 13.2.4

Open
#48,012 4 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Testing
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

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 21.6.0: Thu Sep 29 20:13:56 PDT 2022; root:xnu-8020.240.7~1/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.14.2
      npm: 9.5.0
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.2.5-canary.32
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)

Jest (next/jest)

Link to the code that reproduces this issue

https://github.com/adam187/with-jest-app/tree/not-mocked

To Reproduce
  1. clone the repo
  2. install dependencies (yarn install)
  3. run tests (yarn test)

useTest hook should be automatically mocked from mocks root level folder.

Describe the Bug

Looks like that after upgrading to next.js@13.2.4 https://jestjs.io/docs/manual-mocks stopped working.

Mapping modules without moduleNameMapper works as expected but manual mocks are not resolved instead of real modules.

On version 13.2.3 it's still working as expected: https://github.com/adam187/with-jest-app

Possible source: https://github.com/vercel/next.js/pull/45815

Expected Behavior

Manual mocks should still be loaded and work as described in https://jestjs.io/docs/manual-mocks

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked with-jest-app reproduction, install dependencies with yarn, and run yarn test using the 13.2.4 and 13.2.3 versions. Read the next/jest area and the changes in PR 45815, focusing on resolution of root-level mocks and moduleNameMapper. Done means the useTest manual mock loads again on 13.2.4 and the reproduction tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.