diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index 6506ddbb8e..396e9a0de0 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -78,7 +78,7 @@ declare namespace jest { /** * Mocks a module with an auto-mocked version when it is being required. */ - function doMock(moduleName: string): typeof jest; + function doMock(moduleName: string, factory?: any, options?: MockOptions): typeof jest; /** * Indicates that the module system should never return a mocked version * of the specified module from require() (e.g. that it should always return the real module). diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index ad63cc0a75..2f303c5e8d 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -598,3 +598,19 @@ declare const testResult: jest.TestResult; const myTestRunner: jest.TestFramework = () => Promise.resolve(testResult); const testResultsProcessor: jest.TestResultsProcessor = result => ({...result, numFailedTests: 1}); + +// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18826 +test('moduleName 1', () => { + jest.doMock('../moduleName', () => { + return jest.fn(() => 1); + }); + const moduleName = require('../moduleName'); + expect(moduleName()).toEqual(1); +}); +test('moduleName 2', () => { + jest.doMock('../moduleName', () => { + return jest.fn(() => 2); + }); + const moduleName = require('../moduleName'); + expect(moduleName()).toEqual(2); +});