PokéRogue
    Preparing search index...

    Interface MockContext<T>

    interface MockContext<T extends Procedure | Constructable = Procedure> {
        calls: MockParameters<T>[];
        contexts: MockProcedureContext<T>[];
        instances: MockProcedureContext<T>[];
        invocationCallOrder: number[];
        lastCall: MockParameters<T> | undefined;
        results: MockResult<MockReturnType<T>>[];
        settledResults: MockSettledResult<Awaited<MockReturnType<T>>>[];
    }

    Type Parameters

    Index

    Properties

    calls: MockParameters<T>[]

    This is an array containing all arguments for each call. One item of the array is the arguments of that call.

    const fn = vi.fn()

    fn('arg1', 'arg2')
    fn('arg3')

    fn.mock.calls === [
    ['arg1', 'arg2'], // first call
    ['arg3'], // second call
    ]
    contexts: MockProcedureContext<T>[]

    An array of this values that were used during each call to the mock function.

    instances: MockProcedureContext<T>[]

    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.

    invocationCallOrder: number[]

    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]
    lastCall: MockParameters<T> | undefined

    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, then result will always be 'return' even if the promise was rejected.

    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,
    },
    ]

    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.

    const fn = vi.fn().mockResolvedValueOnce('result')

    const result = fn()

    fn.mock.settledResults === [
    {
    type: 'incomplete',
    value: undefined,
    }
    ]
    fn.mock.results === [
    {
    type: 'return',
    value: Promise<'result'>,
    },
    ]

    await result

    fn.mock.settledResults === [
    {
    type: 'fulfilled',
    value: 'result',
    },
    ]