-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
refactor(jest-mock)!: rework Mocked*
utility types
#13123
Conversation
export type MockedClass<T extends ClassLike> = MockInstance< | ||
(args: T extends new (...args: infer P) => any ? P : never) => InstanceType<T> | ||
> & { | ||
prototype: T extends {prototype: any} ? Mocked<T['prototype']> : never; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be this could be a solution for MockedClassShallow
. Although I am in doubt if it is worse to make types more complicated than proposed in this PR.
// TODO Figure out how to replace this with TS ConstructorParameters utility type | ||
// https://www.typescriptlang.org/docs/handbook/utility-types.html#constructorparameterstype | ||
type ConstructorParameters<T> = T extends new (...args: infer P) => any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ;D
Thanks!! This is awesome |
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. |
Split from #12727
Summary
As noted in #13117 (comment),
jest.mocked()
does not work well with classes.This PR is major refactor of
Mocked*
types which cleans up the implementation and solves the above mentioned issue.To clean up exports the
Mocked*
utility types are renamed.MaybeMockedDeep
andMaybeMocked
becameMocked
andMockedShallow
respectively. Also only deep mocked variants ofMockedClass
,MockedFunction
andMockedObject
are exported.Test plan
Lost of type tests added.