@vitest/spy
Advanced tools
Comparing version 2.0.0-beta.3 to 2.0.0-beta.4
@@ -19,3 +19,12 @@ interface MockResultReturn<T> { | ||
} | ||
interface MockSettledResultFulfilled<T> { | ||
type: 'fulfilled'; | ||
value: T; | ||
} | ||
interface MockSettledResultRejected { | ||
type: 'rejected'; | ||
value: any; | ||
} | ||
type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete; | ||
type MockSettledResult<T> = MockSettledResultFulfilled<T> | MockSettledResultRejected; | ||
interface MockContext<TArgs, TReturns> { | ||
@@ -59,3 +68,3 @@ /** | ||
* | ||
* The `value` property contains the returned value or thrown error. If the function returned a promise, the `value` will be the _resolved_ value, not the actual `Promise`, unless it was never resolved. | ||
* The `value` property contains the returned value or thrown error. If the function returned a `Promise`, then `result` will always be `'return'` even if the promise was rejected. | ||
* | ||
@@ -87,2 +96,30 @@ * @example | ||
/** | ||
* An array containing all values that were `resolved` or `rejected` from the function. | ||
* | ||
* This array will be empty if the function was never resolved or rejected. | ||
* | ||
* @example | ||
* const fn = vi.fn().mockResolvedValueOnce('result') | ||
* | ||
* const result = fn() | ||
* | ||
* fn.mock.settledResults === [] | ||
* fn.mock.results === [ | ||
* { | ||
* type: 'return', | ||
* value: Promise<'result'>, | ||
* }, | ||
* ] | ||
* | ||
* await result | ||
* | ||
* fn.mock.settledResults === [ | ||
* { | ||
* type: 'fulfilled', | ||
* value: 'result', | ||
* }, | ||
* ] | ||
*/ | ||
settledResults: MockSettledResult<Awaited<TReturns>>[]; | ||
/** | ||
* This contains the arguments of the last call. If spy wasn't called, will return `undefined`. | ||
@@ -288,2 +325,2 @@ */ | ||
export { type MaybeMocked, type MaybeMockedConstructor, type MaybeMockedDeep, type MaybePartiallyMocked, type MaybePartiallyMockedDeep, type Mock, type MockContext, type MockInstance, type Mocked, type MockedClass, type MockedFunction, type MockedFunctionDeep, type MockedObject, type MockedObjectDeep, type PartialMock, type PartiallyMockedFunction, type PartiallyMockedFunctionDeep, type SpyInstance, fn, isMockFunction, mocks, spyOn }; | ||
export { type MaybeMocked, type MaybeMockedConstructor, type MaybeMockedDeep, type MaybePartiallyMocked, type MaybePartiallyMockedDeep, type Mock, type MockContext, type MockInstance, type MockResult, type MockSettledResult, type Mocked, type MockedClass, type MockedFunction, type MockedFunctionDeep, type MockedObject, type MockedObjectDeep, type PartialMock, type PartiallyMockedFunction, type PartiallyMockedFunctionDeep, type SpyInstance, fn, isMockFunction, mocks, spyOn }; |
@@ -39,2 +39,8 @@ import * as tinyspy from 'tinyspy'; | ||
}, | ||
get settledResults() { | ||
return state.resolves.map(([callType, value]) => { | ||
const type = callType === "error" ? "rejected" : "fulfilled"; | ||
return { type, value }; | ||
}); | ||
}, | ||
get lastCall() { | ||
@@ -41,0 +47,0 @@ return state.calls[state.calls.length - 1]; |
{ | ||
"name": "@vitest/spy", | ||
"type": "module", | ||
"version": "2.0.0-beta.3", | ||
"version": "2.0.0-beta.4", | ||
"description": "Lightweight Jest compatible spy implementation", | ||
@@ -32,3 +32,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"tinyspy": "^2.2.1" | ||
"tinyspy": "^3.0.0" | ||
}, | ||
@@ -35,0 +35,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
19142
456
+ Addedtinyspy@3.0.2(transitive)
- Removedtinyspy@2.2.1(transitive)
Updatedtinyspy@^3.0.0