@@ -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' ;
89import { childrenOfNode } from './RSTTraversal' ;
@@ -246,7 +247,11 @@ export function cloneElement(adapter, el, props) {
246247export function spyMethod ( instance , methodName ) {
247248 let lastReturnValue ;
248249 const originalMethod = instance [ methodName ] ;
249- const hasOwn = Object . hasOwnProperty . call ( instance , methodName ) ;
250+ const hasOwn = has ( instance , methodName ) ;
251+ let descriptor ;
252+ if ( hasOwn ) {
253+ descriptor = Object . getOwnPropertyDescriptor ( instance , methodName ) ;
254+ }
250255 Object . defineProperty ( instance , methodName , {
251256 configurable : true ,
252257 enumerable : false ,
@@ -259,9 +264,13 @@ export function spyMethod(instance, methodName) {
259264 return {
260265 restore ( ) {
261266 if ( hasOwn ) {
262- /* eslint-disable no-param-reassign */
263- instance [ methodName ] = originalMethod ;
264- /* eslint-enable no-param-reassign */
267+ if ( descriptor ) {
268+ Object . defineProperty ( instance , methodName , descriptor ) ;
269+ } else {
270+ /* eslint-disable no-param-reassign */
271+ instance [ methodName ] = originalMethod ;
272+ /* eslint-enable no-param-reassign */
273+ }
265274 } else {
266275 /* eslint-disable no-param-reassign */
267276 delete instance [ methodName ] ;
0 commit comments