Mocked: {
    [P in keyof T]: T[P] extends (this: infer C, ...args: any[]) => any
        ? MockInstance<ReturnType<T[P]>, ArgsType<T[P]>, C>
        : T[P] extends Constructable ? MockedClass<T[P]> : T[P]
} & T

Wrap an object or a module with mock definitions

Type Parameters

  • T
jest.mock("../api");
import * as api from "../api";

const mockApi = api as jest.Mocked<typeof api>;
api.MyApi.prototype.myApiMethod.mockImplementation(() => "test");