Skip to content

Commit

Permalink
Check _isMockFunction is true rather than truthy
Browse files Browse the repository at this point in the history
Fixes #7009
  • Loading branch information
Dan Ristea committed Sep 23, 2018
1 parent 37caedd commit 328b16a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions packages/jest-mock/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -702,7 +702,7 @@ class ModuleMockerClass {
this._getSlots(component).forEach(slot => {
if (
type === 'function' &&
component._isMockFunction &&
component._isMockFunction === true &&
slot.match(/^mock/)
) {
return;
Expand All @@ -727,7 +727,7 @@ class ModuleMockerClass {
}

isMockFunction(fn: any): boolean {
return !!(fn && fn._isMockFunction);
return !!(fn && fn._isMockFunction === true);
}

fn(implementation?: any): any {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ class Runtime {
(typeof globalMock === 'object' && globalMock !== null) ||
typeof globalMock === 'function'
) {
globalMock._isMockFunction && globalMock.mockClear();
globalMock._isMockFunction === true && globalMock.mockClear();
}
});

Expand Down

0 comments on commit 328b16a

Please sign in to comment.