You can use this helper to mock AND types your class methods.
class A {
foo(a: number, b: number): number { return a + b }
}
const a = mockClass(A.prototype)
a.foo.mockReturnValueOnce(32)| export const mockClass = <T>(prototype: T) => { | |
| const descriptors = Object.getOwnPropertyDescriptors(prototype); | |
| const mockedVersion = Object.fromEntries( | |
| Object.entries(descriptors).map(([key, { value }]) => [key, typeof value === 'function' ? jest.fn() : value]), | |
| ); | |
| return jest.mocked<T>(mockedVersion as T); | |
| }; |