const fn = vi.fn()
fn('arg1', 'arg2')
fn('arg3')
fn.mock.calls === [
['arg1', 'arg2'], // first call
['arg3'], // second call
]
This is an array containing all instances that were instantiated when mock was called with a new keyword. Note that this is an actual context (this) of the function, not a return value.
The order of mock's execution. This returns an array of numbers which are shared between all defined mocks.
const fn1 = vi.fn()
const fn2 = vi.fn()
fn1()
fn2()
fn1()
fn1.mock.invocationCallOrder === [1, 3]
fn2.mock.invocationCallOrder === [2]
This contains the arguments of the last call. If spy wasn't called, will return undefined.
This is an array containing all values that were returned from the function.
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.
const fn = vi.fn()
.mockReturnValueOnce('result')
.mockImplementationOnce(() => { throw new Error('thrown error') })
const result = fn()
try {
fn()
}
catch {}
fn.mock.results === [
{
type: 'return',
value: 'result',
},
{
type: 'throw',
value: Error,
},
]
Generated using TypeDoc
This is an array containing all arguments for each call. One item of the array is the arguments of that call.