jest
jest copied to clipboard
fix(jest-mock): improved `MockedClass` type
Summary
Fixes #14458
added constructor signature in MockedClass type so that it returns
mocked Instance (of type Mocked<InstanceType<typeof original class>>) instead of returning the instance typed with original class type.
Test plan
Tests added
Deploy Preview for jestjs ready!
Built without sensitive environment variables
| Name | Link |
|---|---|
| Latest commit | 3b171f13ab1577ad39e02162cf499932c201ad24 |
| Latest deploy log | https://app.netlify.com/sites/jestjs/deploys/66b0f05b1a208e00080fa4c2 |
| Deploy Preview | https://deploy-preview-15179--jestjs.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
This is failing type tests in packages/jest-types/__typetests__/jest.test.ts
I have run build command multiple times and also see the updated types in build folder,but still all type tests are passing in my local.
After looking at CI failure I found that tests which are using Class.prototype are failing but they are supposed to be passed as MockedObject<T> will provide all typings for the prototype object in a Class.
export type MockedClass<T extends ClassLike> = MockInstance<
(...args: ConstructorParameters<T>) => Mocked<InstanceType<T>>
> &
(new (...args: ConstructorParameters<T>) => Mocked<InstanceType<T>>) &
+ MockedObject<T>;
The type test is failing in CI when using TypeScript 5.0. Locally you can run yarn test-types --target 5.0 to see the same error.
This change is working without issues from Typescript 5.4 and up. You can check this with: yarn test-types --target 5.4,5.5
An easy solution could be to set the lowest supported TypeScript version to 5.4. If @SimenB agrees (;
Otherwise the way forward would be make [email protected] work as well. If that helps, it is possible to use bisect from every-ts with TSTyche to find out which exact comment to TypeScript repo makes this implementation work. (Just for fun, I will try to do this a bit later. Too busy at the moment.)
I'd be down with increasing to 5.2 or something if it'd help, but not 5.4
tests are failing with 5.2, we can hold this PR till jest upgrades ts to 5.4
Otherwise the way forward would be make
[email protected]work as well. If that helps, it is possible to usebisectfrom every-ts with TSTyche to find out which exact comment to TypeScript repo makes this implementation work. (Just for fun, I will try to do this a bit later. Too busy at the moment.)
Or may be try this ...
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.