Skip to content

fix(jest-mock): support promise helpers on overloaded mocks#16207

Open
rohan-patnaik wants to merge 3 commits into
jestjs:mainfrom
rohan-patnaik:fix-overloaded-mock-promise-values
Open

fix(jest-mock): support promise helpers on overloaded mocks#16207
rohan-patnaik wants to merge 3 commits into
jestjs:mainfrom
rohan-patnaik:fix-overloaded-mock-promise-values

Conversation

@rohan-patnaik

Copy link
Copy Markdown

Fixes #16174

Summary

This fixes jest-mock promise helper types for overloaded functions where one overload returns a promise and another returns a non-promise value.

Why

Before this change, helpers like mockResolvedValue, mockRejectedValue, and mockReturnValue used ReturnType<T>. For overloaded functions, TypeScript can collapse that to the callback-style overload, which makes valid promise mocks type as never or void.

Test plan

  • corepack yarn build:ts
  • corepack yarn tstyche packages/jest-mock/__typetests__/Mocked.test.ts
  • corepack yarn eslint --cache packages/jest-mock/src/index.ts packages/jest-mock/__typetests__/Mocked.test.ts
  • corepack yarn prettier --check packages/jest-mock/src/index.ts packages/jest-mock/__typetests__/Mocked.test.ts

@netlify

netlify Bot commented May 22, 2026

Copy link
Copy Markdown

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 64075dd
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/6a100acf69ab48000873a352
😎 Deploy Preview https://deploy-preview-16207--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@linux-foundation-easycla

linux-foundation-easycla Bot commented May 22, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@github-actions github-actions Bot added the require-changelog If a PR does requires a changelog entry label May 22, 2026
@pkg-pr-new

pkg-pr-new Bot commented May 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@16207

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@16207

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@16207

create-jest

npm i https://pkg.pr.new/create-jest@16207

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@16207

expect

npm i https://pkg.pr.new/expect@16207

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@16207

jest

npm i https://pkg.pr.new/jest@16207

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@16207

jest-circus

npm i https://pkg.pr.new/jest-circus@16207

jest-cli

npm i https://pkg.pr.new/jest-cli@16207

jest-config

npm i https://pkg.pr.new/jest-config@16207

@jest/console

npm i https://pkg.pr.new/@jest/console@16207

@jest/core

npm i https://pkg.pr.new/@jest/core@16207

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@16207

jest-diff

npm i https://pkg.pr.new/jest-diff@16207

jest-docblock

npm i https://pkg.pr.new/jest-docblock@16207

jest-each

npm i https://pkg.pr.new/jest-each@16207

@jest/environment

npm i https://pkg.pr.new/@jest/environment@16207

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@16207

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@16207

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@16207

@jest/expect

npm i https://pkg.pr.new/@jest/expect@16207

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@16207

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@16207

@jest/globals

npm i https://pkg.pr.new/@jest/globals@16207

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@16207

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@16207

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@16207

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@16207

jest-message-util

npm i https://pkg.pr.new/jest-message-util@16207

jest-mock

npm i https://pkg.pr.new/jest-mock@16207

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@16207

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@16207

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@16207

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@16207

jest-resolve

npm i https://pkg.pr.new/jest-resolve@16207

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@16207

jest-runner

npm i https://pkg.pr.new/jest-runner@16207

jest-runtime

npm i https://pkg.pr.new/jest-runtime@16207

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@16207

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@16207

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@16207

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@16207

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@16207

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@16207

@jest/transform

npm i https://pkg.pr.new/@jest/transform@16207

@jest/types

npm i https://pkg.pr.new/@jest/types@16207

jest-util

npm i https://pkg.pr.new/jest-util@16207

jest-validate

npm i https://pkg.pr.new/jest-validate@16207

jest-watcher

npm i https://pkg.pr.new/jest-watcher@16207

jest-worker

npm i https://pkg.pr.new/jest-worker@16207

pretty-format

npm i https://pkg.pr.new/pretty-format@16207

commit: 64075dd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

require-changelog If a PR does requires a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Spurious type error when calling mockRejectedValue on mocks of certain overloaded functions

1 participant