@vitest/spy
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0-beta.2
import * as tinyspy from 'tinyspy'; | ||
const vitestSpy = Symbol.for("vitest.spy"); | ||
const mocks = /* @__PURE__ */ new Set(); | ||
@@ -7,2 +8,11 @@ function isMockFunction(fn2) { | ||
} | ||
function getSpy(obj, method, accessType) { | ||
const desc = Object.getOwnPropertyDescriptor(obj, method); | ||
if (desc) { | ||
const fn2 = desc[accessType ?? "value"]; | ||
if (typeof fn2 === "function" && vitestSpy in fn2) { | ||
return fn2; | ||
} | ||
} | ||
} | ||
function spyOn(obj, method, accessType) { | ||
@@ -14,2 +24,6 @@ const dictionary = { | ||
const objMethod = accessType ? { [dictionary[accessType]]: method } : method; | ||
const currentStub = getSpy(obj, method, accessType); | ||
if (currentStub) { | ||
return currentStub; | ||
} | ||
const stub = tinyspy.internalSpyOn(obj, objMethod); | ||
@@ -66,2 +80,6 @@ return enhanceSpy(stub); | ||
let name = stub.name; | ||
Object.defineProperty(stub, vitestSpy, { | ||
value: true, | ||
enumerable: false | ||
}); | ||
stub.getMockName = () => name || "vi.fn()"; | ||
@@ -68,0 +86,0 @@ stub.mockName = (n) => { |
{ | ||
"name": "@vitest/spy", | ||
"type": "module", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.2", | ||
"description": "Lightweight Jest compatible spy implementation", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
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
22349
513