Socket
Socket
Sign inDemoInstall

@vitest/spy

Package Overview
Dependencies
Maintainers
4
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vitest/spy - npm Package Compare versions

Comparing version 2.0.0-beta.3 to 2.0.0-beta.4

41

dist/index.d.ts

@@ -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];

4

package.json
{
"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": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc