Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jest): add createMockFromModule to replace genMockFromModule #46274

Merged
merged 7 commits into from Aug 14, 2020
6 changes: 6 additions & 0 deletions types/jest/index.d.ts
Expand Up @@ -107,6 +107,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 @@ -181,6 +186,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 @@ -368,6 +368,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