jest-mock
Advanced tools
Comparing version 26.6.0 to 26.6.1
@@ -800,18 +800,46 @@ 'use strict'; | ||
const isMethodOwner = object.hasOwnProperty(methodName); // @ts-expect-error overriding original method with a Mock | ||
const isMethodOwner = object.hasOwnProperty(methodName); | ||
let descriptor = Object.getOwnPropertyDescriptor(object, methodName); | ||
let proto = Object.getPrototypeOf(object); | ||
object[methodName] = this._makeComponent( | ||
{ | ||
type: 'function' | ||
}, | ||
() => { | ||
if (isMethodOwner) { | ||
object[methodName] = original; | ||
} else { | ||
delete object[methodName]; | ||
while (!descriptor && proto !== null) { | ||
descriptor = Object.getOwnPropertyDescriptor(proto, methodName); | ||
proto = Object.getPrototypeOf(proto); | ||
} | ||
let mock; | ||
if (descriptor && descriptor.get) { | ||
const originalGet = descriptor.get; | ||
mock = this._makeComponent( | ||
{ | ||
type: 'function' | ||
}, | ||
() => { | ||
descriptor.get = originalGet; | ||
Object.defineProperty(object, methodName, descriptor); | ||
} | ||
} | ||
); // @ts-expect-error original method is now a Mock | ||
); | ||
object[methodName].mockImplementation(function () { | ||
descriptor.get = () => mock; | ||
Object.defineProperty(object, methodName, descriptor); | ||
} else { | ||
mock = this._makeComponent( | ||
{ | ||
type: 'function' | ||
}, | ||
() => { | ||
if (isMethodOwner) { | ||
object[methodName] = original; | ||
} else { | ||
delete object[methodName]; | ||
} | ||
} | ||
); // @ts-expect-error overriding original method with a Mock | ||
object[methodName] = mock; | ||
} | ||
mock.mockImplementation(function () { | ||
return original.apply(this, arguments); | ||
@@ -818,0 +846,0 @@ }); |
{ | ||
"name": "jest-mock", | ||
"version": "26.6.0", | ||
"version": "26.6.1", | ||
"repository": { | ||
@@ -13,3 +13,3 @@ "type": "git", | ||
"dependencies": { | ||
"@jest/types": "^26.6.0", | ||
"@jest/types": "^26.6.1", | ||
"@types/node": "*" | ||
@@ -23,3 +23,3 @@ }, | ||
}, | ||
"gitHead": "b254fd82fdedcba200e1c7eddeaab83a09bdaaef" | ||
"gitHead": "f6366db60e32f1763e612288bf3984bcfa7a0a15" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35350
901
Updated@jest/types@^26.6.1