Skip to content

Commit fe615f1

Browse files
HurricaneJamescpojer
authored andcommitted
fixes bug with enableAutomock when automock is set to false (jestjs#3624)
1 parent b6a63a0 commit fe615f1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/jest-runtime/src/__tests__/Runtime-requireModuleOrMock-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,18 @@ it('automocking is disabled by default', () =>
160160
);
161161
expect(exports.setModuleStateValue._isMockFunction).toBe(undefined);
162162
}));
163+
164+
it('unmocks modules in config.unmockedModulePathPatterns for tests with automock enabled when automock is false', () =>
165+
createRuntime(__filename, {
166+
automock: false,
167+
moduleNameMapper,
168+
unmockedModulePathPatterns: ['npm3-main-dep'],
169+
}).then(runtime => {
170+
const root = runtime.requireModule(runtime.__mockRootPath);
171+
root.jest.enableAutomock();
172+
const nodeModule = runtime.requireModuleOrMock(runtime.__mockRootPath, 'npm3-main-dep');
173+
const moduleData = nodeModule();
174+
expect(moduleData.isUnmocked()).toBe(true);
175+
})
176+
);
177+

packages/jest-runtime/src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ class Runtime {
146146
this._unmockList = unmockRegExpCache.get(config);
147147
if (
148148
!this._unmockList &&
149-
config.automock &&
150149
config.unmockedModulePathPatterns
151150
) {
152151
this._unmockList = new RegExp(

0 commit comments

Comments
 (0)