MockFunctionContext

external class MockFunctionContext<F : Function<*>>(source)

The MockFunctionContext class is used to inspect or manipulate the behavior of mocks created via the MockTracker APIs.

Since

v19.1.0, v18.13.0

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

A getter that returns a copy of the internal array used to track calls to the mock. Each entry in the array is an object with the following properties.

Functions

Link copied to clipboard

This function returns the number of times that this mock has been invoked. This function is more efficient than checking ctx.calls.length because ctx.calls is a getter that creates a copy of the internal call tracking array.

Link copied to clipboard
fun mockImplementation(implementation: F)

This function is used to change the behavior of an existing mock.

Link copied to clipboard
fun mockImplementationOnce(implementation: F, onCall: Number = definedExternally)

This function is used to change the behavior of an existing mock for a single invocation. Once invocation onCall has occurred, the mock will revert to whatever behavior it would have used had mockImplementationOnce() not been called.

Link copied to clipboard

Resets the call history of the mock function.

Link copied to clipboard
fun restore()

Resets the implementation of the mock function to its original behavior. The mock can still be used after calling this function.