fix(jest-mock): type constructed mocked class instances#16212
fix(jest-mock): type constructed mocked class instances#16212KirtiRamchandani wants to merge 1 commit into
Conversation
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
31e2a7b to
b8f301e
Compare
babel-jest
babel-plugin-jest-hoist
babel-preset-jest
create-jest
@jest/diff-sequences
expect
@jest/expect-utils
jest
jest-changed-files
jest-circus
jest-cli
jest-config
@jest/console
@jest/core
@jest/create-cache-key-function
jest-diff
jest-docblock
jest-each
@jest/environment
jest-environment-jsdom
@jest/environment-jsdom-abstract
jest-environment-node
@jest/expect
@jest/fake-timers
@jest/get-type
@jest/globals
jest-haste-map
jest-jasmine2
jest-leak-detector
jest-matcher-utils
jest-message-util
jest-mock
@jest/pattern
jest-phabricator
jest-regex-util
@jest/reporters
jest-resolve
jest-resolve-dependencies
jest-runner
jest-runtime
@jest/schemas
jest-snapshot
@jest/snapshot-utils
@jest/source-map
@jest/test-result
@jest/test-sequencer
@jest/transform
@jest/types
jest-util
jest-validate
jest-watcher
jest-worker
pretty-format
commit: |
|
The remaining CI failure looks unrelated to this PR's type-only change. The failed I don't see a code change needed in this branch from that log; this looks like a macOS/Node runner crash and should be safe to rerun. |
Summary
Fixes #14458.
MockedClass<T>already typed mock calls with constructor parameters, but it did not expose a construct signature returning a mocked instance. As a result, constructing a class returned byModuleMocker.generateFromMetadata()was typed as the original instance type, so mocked methods likeinstance.memberB.mockwere missing at the type level even though they exist at runtime.This adds the missing construct signature and covers the regression in the
jest-mockTSTyche tests.Test plan
corepack yarn tsc -b packages\expect-utils packages\jest-types packages\jest-util packages\jest-mockcorepack yarn tstyche packages\jest-mock\__typetests__\ModuleMocker.test.ts packages\jest-mock\__typetests__\Mocked.test.tscorepack yarn tstyche packages/jest-mock/__typetests__corepack yarn eslint packages\jest-mock\src\index.ts packages\jest-mock\__typetests__\ModuleMocker.test.tscorepack yarn jest packages\jest-mock\src\__tests__\index.test.ts --runInBandgit diff --check