From 37bdf313cba30cc6a351dd82394493600fd96e5d Mon Sep 17 00:00:00 2001 From: Clemens Pflaum Date: Mon, 29 May 2023 10:23:44 +0200 Subject: [PATCH] fix(types): fix `PartialMock` with async TReturns close #3461 --- packages/spy/src/index.ts | 2 +- test/core/test/vi.spec.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/spy/src/index.ts b/packages/spy/src/index.ts index d077893df3ea..54af57cfec66 100644 --- a/packages/spy/src/index.ts +++ b/packages/spy/src/index.ts @@ -62,7 +62,7 @@ export interface Mock extends SpyInst new (...args: TArgs): TReturns (...args: TArgs): TReturns } -export interface PartialMock extends SpyInstance> { +export interface PartialMock extends SpyInstance> ? Promise>> : Partial> { new (...args: TArgs): TReturns (...args: TArgs): TReturns } diff --git a/test/core/test/vi.spec.ts b/test/core/test/vi.spec.ts index 5b038da725e6..d938c7b32f9c 100644 --- a/test/core/test/vi.spec.ts +++ b/test/core/test/vi.spec.ts @@ -65,6 +65,22 @@ describe('testing vi utils', () => { vi.mocked(mockFactory, { partial: true, deep: true }).mockReturnValue({ baz: 'baz', }) + + type FooBarAsyncFactory = () => Promise + + const mockFactoryAsync: FooBarAsyncFactory = vi.fn() + + vi.mocked(mockFactoryAsync, { partial: true }).mockResolvedValue({ + foo: vi.fn(), + }) + + vi.mocked(mockFactoryAsync, { partial: true, deep: false }).mockResolvedValue({ + bar: vi.fn(), + }) + + vi.mocked(mockFactoryAsync, { partial: true, deep: true }).mockResolvedValue({ + baz: 'baz', + }) }) test('can change config', () => {