Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#46274 fix(jest): add `createMockFromModule…
Browse files Browse the repository at this point in the history
…` to replace `genMockFromModule` by @CoolCyberBrain

* 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 875b63a.

* Revert "Revert "docs(jest): remove deprecated tag""

This reverts commit 0fb5fc3.
  • Loading branch information
Calvin-LL authored and danielrearden committed Sep 22, 2020
1 parent df210e8 commit 340e820
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions types/jest/index.d.ts
Expand Up @@ -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<T>(moduleName: string): T;
/**
* Resets the state of all mocks.
* Equivalent to calling .mockReset() on every mocked function.
Expand Down Expand Up @@ -163,6 +168,7 @@ declare namespace jest {
*/
function fn<T, Y extends any[]>(implementation?: (...args: Y) => T): Mock<T, Y>;
/**
* (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
Expand Down
3 changes: 3 additions & 0 deletions types/jest/jest-tests.ts
Expand Up @@ -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');

Expand Down

0 comments on commit 340e820

Please sign in to comment.