Skip to content

Commit

Permalink
test: fix failing tests for spyOnProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
phra committed Dec 18, 2017
1 parent 9c751da commit 38860c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion flow-typed/npm/jest_v21.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ declare var expect: {
// TODO handle return type
// http://jasmine.github.io/2.4/introduction.html#section-Spies
declare function spyOn(value: mixed, method: string): Object;
declare function spyOnProperty(value: mixed, propertyName: string, accessType: 'get' | 'set'): Object;
declare function spyOnProperty(value: mixed, propertyName: string, accessType: string): Object;

/** Holds all functions related to manipulating test runner */
declare var jest: JestObjectType;
Expand Down
15 changes: 5 additions & 10 deletions packages/jest-mock/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,10 +691,10 @@ class ModuleMockerClass {
return object[methodName];
}

spyOnProperty(object: any, propertyName: any, accessType = 'get'): any {
if (typeof object !== 'object' && typeof object !== 'function') {
spyOnProperty(obj: any, propertyName: any, accessType: string = 'get'): any {
if (typeof obj !== 'object' && typeof obj !== 'function') {
throw new Error(
'Cannot spyOn on a primitive value; ' + this._typeOf(object) + ' given',
'Cannot spyOn on a primitive value; ' + this._typeOf(obj) + ' given',
);
}

Expand All @@ -706,12 +706,7 @@ class ModuleMockerClass {
throw new Error('No property name supplied');
}

let descriptor;
try {
descriptor = Object.getOwnPropertyDescriptor(obj, propertyName);
} catch (e) {
// IE 8 doesn't support `definePropery` on non-DOM nodes
}
const descriptor = Object.getOwnPropertyDescriptor(obj, propertyName);

if (!descriptor) {
throw new Error(propertyName + ' property does not exist');
Expand All @@ -731,7 +726,7 @@ class ModuleMockerClass {
if (typeof original !== 'function') {
throw new Error(
'Cannot spy the ' +
methodName +
propertyName +
' property because it is not a function; ' +
this._typeOf(original) +
' given instead',
Expand Down

0 comments on commit 38860c7

Please sign in to comment.