From 38860c782afcf67d11cd227694a06871385c09a7 Mon Sep 17 00:00:00 2001 From: phra Date: Mon, 18 Dec 2017 21:24:50 +0100 Subject: [PATCH] test: fix failing tests for spyOnProperty --- flow-typed/npm/jest_v21.x.x.js | 2 +- packages/jest-mock/src/index.js | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/flow-typed/npm/jest_v21.x.x.js b/flow-typed/npm/jest_v21.x.x.js index 8dc63523cd46..ceb0799324c1 100644 --- a/flow-typed/npm/jest_v21.x.x.js +++ b/flow-typed/npm/jest_v21.x.x.js @@ -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; diff --git a/packages/jest-mock/src/index.js b/packages/jest-mock/src/index.js index 4e490bc9b216..2bbfc4316ca8 100644 --- a/packages/jest-mock/src/index.js +++ b/packages/jest-mock/src/index.js @@ -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', ); } @@ -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'); @@ -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',