@@ -3,6 +3,7 @@ import isEqual from 'lodash/isEqual';
33import is from 'object-is' ;
44import entries from 'object.entries' ;
55import functionName from 'function.prototype.name' ;
6+ import has from 'has' ;
67import configuration from './configuration' ;
78import validateAdapter from './validateAdapter' ;
89
@@ -270,7 +271,11 @@ export function cloneElement(adapter, el, props) {
270271export function spyMethod ( instance , methodName ) {
271272 let lastReturnValue ;
272273 const originalMethod = instance [ methodName ] ;
273- const hasOwn = Object . hasOwnProperty . call ( instance , methodName ) ;
274+ const hasOwn = has ( instance , methodName ) ;
275+ let descriptor ;
276+ if ( hasOwn ) {
277+ descriptor = Object . getOwnPropertyDescriptor ( instance , methodName ) ;
278+ }
274279 Object . defineProperty ( instance , methodName , {
275280 configurable : true ,
276281 enumerable : false ,
@@ -283,9 +288,13 @@ export function spyMethod(instance, methodName) {
283288 return {
284289 restore ( ) {
285290 if ( hasOwn ) {
286- /* eslint-disable no-param-reassign */
287- instance [ methodName ] = originalMethod ;
288- /* eslint-enable no-param-reassign */
291+ if ( descriptor ) {
292+ Object . defineProperty ( instance , methodName , descriptor ) ;
293+ } else {
294+ /* eslint-disable no-param-reassign */
295+ instance [ methodName ] = originalMethod ;
296+ /* eslint-enable no-param-reassign */
297+ }
289298 } else {
290299 /* eslint-disable no-param-reassign */
291300 delete instance [ methodName ] ;
0 commit comments