Skip to content
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

types: wrong generic type params in type MockedClass #1730

Closed
6 tasks done
Tanimodori opened this issue Jul 27, 2022 · 1 comment · Fixed by #1735
Closed
6 tasks done

types: wrong generic type params in type MockedClass #1730

Tanimodori opened this issue Jul 27, 2022 · 1 comment · Fixed by #1735

Comments

@Tanimodori
Copy link
Contributor

Tanimodori commented Jul 27, 2022

Describe the bug

The primary part of MockedClass<T> is MockInstance<InstanceType<T>, ConstructorArgs<T>>

export type MockedClass<T extends Constructable> = MockInstance<
InstanceType<T>,
T extends new (...args: infer P) => any ? P : never
> & {
prototype: T extends { prototype: any } ? Mocked<T['prototype']> : never
} & T

But I think MockInstance<A, R> which is primarily SpyInstance<TArgs, TReturns> is a kind of mock new (...Targs)=>TReturns, should MockedClass<T> be MockInstance<ConstructorArgs<T>, InstanceType<T>> instead of MockInstance<InstanceType<T>, ConstructorArgs<T>>?

export interface SpyInstance<TArgs extends any[] = any[], TReturns = any> {
getMockName(): string
mockName(n: string): this
mock: MockContext<TArgs, TReturns>
mockClear(): this
mockReset(): this
mockRestore(): void
getMockImplementation(): ((...args: TArgs) => TReturns) | undefined
mockImplementation(fn: ((...args: TArgs) => TReturns) | (() => Promise<TReturns>)): this
mockImplementationOnce(fn: ((...args: TArgs) => TReturns) | (() => Promise<TReturns>)): this
mockReturnThis(): this
mockReturnValue(obj: TReturns): this
mockReturnValueOnce(obj: TReturns): this
mockResolvedValue(obj: Awaited<TReturns>): this
mockResolvedValueOnce(obj: Awaited<TReturns>): this
mockRejectedValue(obj: any): this
mockRejectedValueOnce(obj: any): this
}

export interface MockInstance<A extends any[] = any[], R = any> extends SpyInstance<A, R> {}

Reproduction

n/a

System Info

n/a

Used Package Manager

npm

Validations

@sheremet-va
Copy link
Member

Yes, I think you are right. PR welcome.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants