Skip to content

Commit 9092664

Browse files
purepearhi-ogawa
andauthored
fix: type regression in vi.mocked() static class methods (#9857)
Co-authored-by: Hiroshi Ogawa <hi.ogawa.zz@gmail.com>
1 parent 58e64d5 commit 9092664

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/spy/src/types.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,10 @@ type DeepPartialMock<T extends Procedure | Constructable = Procedure> = Mock<
462462
export type MaybeMockedConstructor<T> = T extends Constructable
463463
? Mock<T>
464464
: T
465-
export type MockedFunction<T extends Procedure | Constructable> = Mock<T> & {
466-
[K in keyof T]: T[K];
467-
}
468-
export type PartiallyMockedFunction<T extends Procedure | Constructable> = PartialMock<T> & {
469-
[K in keyof T]: T[K];
470-
}
465+
export type MockedFunction<T extends Procedure | Constructable> = Mock<T>
466+
& MockedObject<T>
467+
export type PartiallyMockedFunction<T extends Procedure | Constructable> = PartialMock<T>
468+
& MockedObject<T>
471469
export type MockedFunctionDeep<T extends Procedure | Constructable> = Mock<T>
472470
& MockedObjectDeep<T>
473471
export type PartiallyMockedFunctionDeep<T extends Procedure | Constructable> = DeepPartialMock<T>

test/core/test/vi.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ describe('testing vi utils', () => {
151151
public getBar(): string {
152152
return this.bar
153153
}
154+
155+
static getBaz(): string {
156+
return 'baz'
157+
}
154158
}
155159
class FooMock implements Mocked<Foo> {
156160
readonly barMock: Mock<() => string> = vi.fn()
@@ -168,6 +172,8 @@ describe('testing vi utils', () => {
168172
if (0) {
169173
vi.mocked(Foo).mockImplementation(FooMock)
170174
vi.mocked(Foo).mockImplementation(Foo)
175+
vi.mocked(Foo).getBaz.mockImplementation(() => 'baz')
176+
vi.mocked(Foo, { partial: true }).getBaz.mockImplementation(() => 'baz')
171177
}
172178
})
173179

0 commit comments

Comments
 (0)