fix(jest): add missing arguments for jest.doMock() (#18830)

This commit is contained in:
Ika
2017-08-14 11:14:15 -07:00
committed by Mohamed Hegazy
parent 84e67a17f6
commit 00e167da06
2 changed files with 17 additions and 1 deletions
+1 -1
View File
@@ -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).
+16
View File
@@ -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);
});