diff --git a/jest/index.d.ts b/jest/index.d.ts index e81a08c1ca..020376004b 100644 --- a/jest/index.d.ts +++ b/jest/index.d.ts @@ -201,15 +201,10 @@ declare namespace jest { * * const myApi: jest.Mocked = new Api() as any; * myApi.myApiMethod.mockImplementation(() => "test"); - * - * jest.mock("./func"); - * const myFuncMock: jest.Mocked = require("./func"); - * myFuncMock.mockImplementation(() => 5); - * myFuncMock(); */ type Mocked = T & { [P in keyof T]: T[P] & MockInstance; - } & MockInstance; + }; interface MockInstance { mock: MockContext; diff --git a/jest/jest-tests.ts b/jest/jest-tests.ts index c42df8fef4..d2fcd6d007 100644 --- a/jest/jest-tests.ts +++ b/jest/jest-tests.ts @@ -426,28 +426,20 @@ describe('strictNullChecks', function () { }) }); -interface TestApi { +class TestApi { + constructor() { }; testProp: boolean; - testMethod(a: number): void; + testMethod(a: number): string { return ""; } } declare function mockedFunc(a: number): string; describe('Mocked type', function () { it('Works', function () { - const mock: jest.Mocked = jest.fn(() => ({ - testProp: true, - testMethod1: jest.fn(), - testMethod2: jest.fn() - })) as any; + const mock: jest.Mocked = new TestApi() as any; mock.testProp; mock.testMethod.mockImplementation(() => 'test'); - mock.testMethod(5); - mock.mockClear(); - - const funcMock: jest.Mocked = require('./mockedFunc'); - funcMock.mockImplementation(() => 'test'); - funcMock(5).toUpperCase(); + mock.testMethod(5).toUpperCase(); }); });