From 234b0dde62a6ccf1f12a1ec80f7df7dc8eceeea7 Mon Sep 17 00:00:00 2001 From: Delyan Haralanov Date: Thu, 12 Mar 2026 22:36:57 +0200 Subject: [PATCH] fix: type regression in vi.mocked() static class methods --- packages/spy/src/types.ts | 10 ++++------ test/core/test/vi.spec.ts | 6 ++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/spy/src/types.ts b/packages/spy/src/types.ts index 2646e13f2dd2..14b9d4dc3b3d 100644 --- a/packages/spy/src/types.ts +++ b/packages/spy/src/types.ts @@ -462,12 +462,10 @@ type DeepPartialMock = Mock< export type MaybeMockedConstructor = T extends Constructable ? Mock : T -export type MockedFunction = Mock & { - [K in keyof T]: T[K]; -} -export type PartiallyMockedFunction = PartialMock & { - [K in keyof T]: T[K]; -} +export type MockedFunction = Mock + & MockedObject +export type PartiallyMockedFunction = PartialMock + & MockedObject export type MockedFunctionDeep = Mock & MockedObjectDeep export type PartiallyMockedFunctionDeep = DeepPartialMock diff --git a/test/core/test/vi.spec.ts b/test/core/test/vi.spec.ts index 0ef0ab55085d..ed642430b29c 100644 --- a/test/core/test/vi.spec.ts +++ b/test/core/test/vi.spec.ts @@ -151,6 +151,10 @@ describe('testing vi utils', () => { public getBar(): string { return this.bar } + + static getBaz(): string { + return 'baz' + } } class FooMock implements Mocked { readonly barMock: Mock<() => string> = vi.fn() @@ -168,6 +172,8 @@ describe('testing vi utils', () => { if (0) { vi.mocked(Foo).mockImplementation(FooMock) vi.mocked(Foo).mockImplementation(Foo) + vi.mocked(Foo).getBaz.mockImplementation(() => 'baz') + vi.mocked(Foo, { partial: true }).getBaz.mockImplementation(() => 'baz') } })