Skip to content

Commit 38860c7

Browse files
committed
test: fix failing tests for spyOnProperty
1 parent 9c751da commit 38860c7

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

flow-typed/npm/jest_v21.x.x.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ declare var expect: {
555555
// TODO handle return type
556556
// http://jasmine.github.io/2.4/introduction.html#section-Spies
557557
declare function spyOn(value: mixed, method: string): Object;
558-
declare function spyOnProperty(value: mixed, propertyName: string, accessType: 'get' | 'set'): Object;
558+
declare function spyOnProperty(value: mixed, propertyName: string, accessType: string): Object;
559559

560560
/** Holds all functions related to manipulating test runner */
561561
declare var jest: JestObjectType;

packages/jest-mock/src/index.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -691,10 +691,10 @@ class ModuleMockerClass {
691691
return object[methodName];
692692
}
693693

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

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

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

716711
if (!descriptor) {
717712
throw new Error(propertyName + ' property does not exist');
@@ -731,7 +726,7 @@ class ModuleMockerClass {
731726
if (typeof original !== 'function') {
732727
throw new Error(
733728
'Cannot spy the ' +
734-
methodName +
729+
propertyName +
735730
' property because it is not a function; ' +
736731
this._typeOf(original) +
737732
' given instead',

0 commit comments

Comments
 (0)