@vitest/spy
Advanced tools
Comparing version 0.29.8 to 0.30.0
@@ -1,2 +0,2 @@ | ||
import { SpyImpl } from 'tinyspy'; | ||
import { SpyInternalImpl } from 'tinyspy'; | ||
@@ -96,3 +96,3 @@ interface MockResultReturn<T> { | ||
} & T; | ||
type EnhancedSpy<TArgs extends any[] = any[], TReturns = any> = SpyInstance<TArgs, TReturns> & SpyImpl<TArgs, TReturns>; | ||
type EnhancedSpy<TArgs extends any[] = any[], TReturns = any> = SpyInstance<TArgs, TReturns> & SpyInternalImpl<TArgs, TReturns>; | ||
declare const spies: Set<SpyInstance<any[], any>>; | ||
@@ -99,0 +99,0 @@ declare function isMockFunction(fn: any): fn is EnhancedSpy; |
@@ -13,3 +13,3 @@ import * as tinyspy from 'tinyspy'; | ||
const objMethod = accessType ? { [dictionary[accessType]]: method } : method; | ||
const stub = tinyspy.spyOn(obj, objMethod); | ||
const stub = tinyspy.internalSpyOn(obj, objMethod); | ||
return enhanceSpy(stub); | ||
@@ -23,5 +23,6 @@ } | ||
let invocations = []; | ||
const state = tinyspy.getInternalState(spy); | ||
const mockContext = { | ||
get calls() { | ||
return stub.calls; | ||
return state.calls; | ||
}, | ||
@@ -35,3 +36,3 @@ get instances() { | ||
get results() { | ||
return stub.results.map(([callType, value]) => { | ||
return state.results.map(([callType, value]) => { | ||
const type = callType === "error" ? "throw" : "return"; | ||
@@ -42,3 +43,3 @@ return { type, value }; | ||
get lastCall() { | ||
return stub.calls[stub.calls.length - 1]; | ||
return state.calls[state.calls.length - 1]; | ||
} | ||
@@ -55,3 +56,3 @@ }; | ||
stub.mockClear = () => { | ||
stub.reset(); | ||
state.reset(); | ||
instances = []; | ||
@@ -112,6 +113,6 @@ invocations = []; | ||
}); | ||
stub.willCall(function(...args) { | ||
state.willCall(function(...args) { | ||
instances.push(this); | ||
invocations.push(++callOrder); | ||
const impl = implementationChangedTemporarily ? implementation : onceImplementations.shift() || implementation || stub.getOriginal() || (() => { | ||
const impl = implementationChangedTemporarily ? implementation : onceImplementations.shift() || implementation || state.getOriginal() || (() => { | ||
}); | ||
@@ -124,3 +125,3 @@ return impl.apply(this, args); | ||
function fn(implementation) { | ||
return enhanceSpy(tinyspy.spyOn({ fn: implementation || (() => { | ||
return enhanceSpy(tinyspy.internalSpyOn({ fn: implementation || (() => { | ||
}) }, "fn")); | ||
@@ -127,0 +128,0 @@ } |
{ | ||
"name": "@vitest/spy", | ||
"type": "module", | ||
"version": "0.29.8", | ||
"version": "0.30.0", | ||
"description": "Lightweight Jest compatible spy implementation", | ||
@@ -27,3 +27,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"tinyspy": "^1.0.2" | ||
"tinyspy": "^2.1.0" | ||
}, | ||
@@ -30,0 +30,0 @@ "scripts": { |
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
14667
6
348
+ Addedtinyspy@2.2.1(transitive)
- Removedtinyspy@1.1.1(transitive)
Updatedtinyspy@^2.1.0