From 340e8209dc0f306d24327691821bfc03c9652b87 Mon Sep 17 00:00:00 2001 From: Calvin Liang Date: Fri, 14 Aug 2020 16:39:20 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#46274=20fix(jest):?= =?UTF-8?q?=20add=20`createMockFromModule`=20to=20replace=20`genMockFromMo?= =?UTF-8?q?dule`=20by=20@CoolCyberBrain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(jest): add `createMockFromModule` to replace `genMockFromModule` * test(jest): add test for `jest.createMockFromModule` * style(jest): remove trailing whitespace * docs(jest): remove deprecated tag * Revert "docs(jest): remove deprecated tag" This reverts commit 875b63acf3e7873afd4051c87e02cff09c3bdd4a. * Revert "Revert "docs(jest): remove deprecated tag"" This reverts commit 0fb5fc3a48579f5f307aca4fa96ebc051e1520c8. --- types/jest/index.d.ts | 6 ++++++ types/jest/jest-tests.ts | 3 +++ 2 files changed, 9 insertions(+) diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index 3ca683b3118d84b..097eef11a5b135a 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -89,6 +89,11 @@ declare namespace jest { * Equivalent to calling .mockClear() on every mocked function. */ function clearAllMocks(): typeof jest; + /** + * Use the automatic mocking system to generate a mocked version of the given module. + */ + // tslint:disable-next-line: no-unnecessary-generics + function createMockFromModule(moduleName: string): T; /** * Resets the state of all mocks. * Equivalent to calling .mockReset() on every mocked function. @@ -163,6 +168,7 @@ declare namespace jest { */ function fn(implementation?: (...args: Y) => T): Mock; /** + * (renamed to `createMockFromModule` in Jest 26.0.0+) * Use the automatic mocking system to generate a mocked version of the given module. */ // tslint:disable-next-line: no-unnecessary-generics diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index ac6902dccac8073..dd449d93399669f 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -358,6 +358,9 @@ mock8.mockImplementation((arg: string) => 1); // mockImplementation not required to declare all arguments mock9.mockImplementation((a: number) => Promise.resolve(a === 0)); +const createMockFromModule1: {} = jest.createMockFromModule('moduleName'); +const createMockFromModule2: { a: 'b' } = jest.createMockFromModule<{ a: 'b' }>('moduleName'); + const genMockModule1: {} = jest.genMockFromModule('moduleName'); const genMockModule2: { a: 'b' } = jest.genMockFromModule<{ a: 'b' }>('moduleName');