diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a6ce07e7b5a..30fdd030c1c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - `[jest-mock]` Fix inheritance of static properties and methods in mocks ([#7003](https://github.com/facebook/jest/pull/7003)) - `[jest-mock]` Fix mocking objects without `Object.prototype` in their prototype chain ([#7003](https://github.com/facebook/jest/pull/7003)) - `[jest-cli]` Update jest-cli to show git ref in message when using `changedSince` ([#7028](https://github.com/facebook/jest/pull/7028)) +- `[jest-runtime]` Check `globalMock._isMockFunction` is true rather than truthy ([#7017](https://github.com/facebook/jest/pull/7017)) ### Chore & Maintenance diff --git a/packages/jest-mock/src/index.js b/packages/jest-mock/src/index.js index 39bb7a8a8d02..70e8260a0df3 100644 --- a/packages/jest-mock/src/index.js +++ b/packages/jest-mock/src/index.js @@ -687,7 +687,7 @@ class ModuleMockerClass { return metadata; } else if (type === 'function') { metadata.name = component.name; - if (component._isMockFunction) { + if (component._isMockFunction === true) { metadata.mockImpl = component.getMockImplementation(); } } @@ -702,7 +702,7 @@ class ModuleMockerClass { this._getSlots(component).forEach(slot => { if ( type === 'function' && - component._isMockFunction && + component._isMockFunction === true && slot.match(/^mock/) ) { return; @@ -727,7 +727,7 @@ class ModuleMockerClass { } isMockFunction(fn: any): boolean { - return !!(fn && fn._isMockFunction); + return !!(fn && fn._isMockFunction === true); } fn(implementation?: any): any { diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index d6612eb42221..507da20aa247 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -430,7 +430,7 @@ class Runtime { (typeof globalMock === 'object' && globalMock !== null) || typeof globalMock === 'function' ) { - globalMock._isMockFunction && globalMock.mockClear(); + globalMock._isMockFunction === true && globalMock.mockClear(); } });