From b3413ef80d6acd2ca9e8df8a01d3065f7d60c3f7 Mon Sep 17 00:00:00 2001 From: James Burnett Date: Mon, 22 May 2017 15:14:10 +0100 Subject: [PATCH] fixes bug with enableAutomock when automock is set to false --- .../__tests__/Runtime-requireModuleOrMock-test.js | 15 +++++++++++++++ packages/jest-runtime/src/index.js | 1 - 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/jest-runtime/src/__tests__/Runtime-requireModuleOrMock-test.js b/packages/jest-runtime/src/__tests__/Runtime-requireModuleOrMock-test.js index 6ab65c7110ed..0bc25d077e6a 100644 --- a/packages/jest-runtime/src/__tests__/Runtime-requireModuleOrMock-test.js +++ b/packages/jest-runtime/src/__tests__/Runtime-requireModuleOrMock-test.js @@ -160,3 +160,18 @@ it('automocking is disabled by default', () => ); expect(exports.setModuleStateValue._isMockFunction).toBe(undefined); })); + +it('unmocks modules in config.unmockedModulePathPatterns for tests with automock enabled when automock is false', () => + createRuntime(__filename, { + automock: false, + moduleNameMapper, + unmockedModulePathPatterns: ['npm3-main-dep'], + }).then(runtime => { + const root = runtime.requireModule(runtime.__mockRootPath); + root.jest.enableAutomock(); + const nodeModule = runtime.requireModuleOrMock(runtime.__mockRootPath, 'npm3-main-dep'); + const moduleData = nodeModule(); + expect(moduleData.isUnmocked()).toBe(true); + }) +); + diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index 1c0becd5a8ee..c669fb25b347 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -146,7 +146,6 @@ class Runtime { this._unmockList = unmockRegExpCache.get(config); if ( !this._unmockList && - config.automock && config.unmockedModulePathPatterns ) { this._unmockList = new RegExp(