@vitest/spy
Advanced tools
Comparing version 2.0.0-beta.10 to 2.0.0-beta.11
@@ -186,3 +186,3 @@ interface MockResultReturn<T> { | ||
*/ | ||
mockImplementation: (fn: ((...args: TArgs) => TReturns)) => this; | ||
mockImplementation: (fn: (...args: TArgs) => TReturns) => this; | ||
/** | ||
@@ -195,3 +195,3 @@ * Accepts a function that will be used as a mock implementation during the next call. Can be chained so that multiple function calls produce different results. | ||
*/ | ||
mockImplementationOnce: (fn: ((...args: TArgs) => TReturns)) => this; | ||
mockImplementationOnce: (fn: (...args: TArgs) => TReturns) => this; | ||
/** | ||
@@ -208,3 +208,3 @@ * Overrides the original mock implementation temporarily while the callback is being executed. | ||
*/ | ||
withImplementation: <T>(fn: ((...args: TArgs) => TReturns), cb: () => T) => T extends Promise<unknown> ? Promise<this> : this; | ||
withImplementation: <T>(fn: (...args: TArgs) => TReturns, cb: () => T) => T extends Promise<unknown> ? Promise<this> : this; | ||
/** | ||
@@ -319,5 +319,5 @@ * Use this if you need to return `this` context from the method without invoking actual implementation. | ||
declare function spyOn<T, G extends Properties<Required<T>>>(obj: T, methodName: G, accessType: 'set'): MockInstance<[T[G]], void>; | ||
declare function spyOn<T, M extends (Classes<Required<T>> | Methods<Required<T>>)>(obj: T, methodName: M): Required<T>[M] extends ({ | ||
declare function spyOn<T, M extends Classes<Required<T>> | Methods<Required<T>>>(obj: T, methodName: M): Required<T>[M] extends { | ||
new (...args: infer A): infer R; | ||
}) | ((...args: infer A) => infer R) ? MockInstance<A, R> : never; | ||
} | ((...args: infer A) => infer R) ? MockInstance<A, R> : never; | ||
declare function fn<TArgs extends any[] = any, R = any>(): Mock<TArgs, R>; | ||
@@ -324,0 +324,0 @@ declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): Mock<TArgs, R>; |
@@ -129,6 +129,9 @@ import * as tinyspy from 'tinyspy'; | ||
function fn(implementation) { | ||
const enhancedSpy = enhanceSpy(tinyspy.internalSpyOn({ spy: implementation || (() => { | ||
}) }, "spy")); | ||
if (implementation) | ||
const enhancedSpy = enhanceSpy( | ||
tinyspy.internalSpyOn({ spy: implementation || (() => { | ||
}) }, "spy") | ||
); | ||
if (implementation) { | ||
enhancedSpy.mockImplementation(implementation); | ||
} | ||
return enhancedSpy; | ||
@@ -135,0 +138,0 @@ } |
{ | ||
"name": "@vitest/spy", | ||
"type": "module", | ||
"version": "2.0.0-beta.10", | ||
"version": "2.0.0-beta.11", | ||
"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
19149
459