MockInstance
interface in meocord/testing Since 4.0.0
interface MockInstance<
T extends (...args: any[]) => any = (...args: any[]) => any,
>The mock API of a mock function: what it has recorded, and the methods that change what it does.
Every mock from meocord/testing has it, with the names jest and Vitest use, so a test written for either runner
reads the same.
Members
_isMockFunction
readonly _isMockFunction: trueMarks the function as a mock for jest and Vitest, which check it through isMockFunction.
mock
readonly mock: MockState<T>What the mock has recorded: its calls, their outcomes and their this.
mockReturnValue
mockReturnValue(value: CallResult<T>): MockedFunction<T>Returns value from every call, until another implementation is set.
Parameters
| Name | Type | Description |
|---|---|---|
value | CallResult<T> |
Returns
MockedFunction<T>mockReturnValueOnce
mockReturnValueOnce(value: CallResult<T>): MockedFunction<T>Returns value from the next call only.
Parameters
| Name | Type | Description |
|---|---|---|
value | CallResult<T> |
Returns
MockedFunction<T>mockResolvedValue
mockResolvedValue(value: Awaited<CallResult<T>>): MockedFunction<T>Resolves every call to value.
Parameters
| Name | Type | Description |
|---|---|---|
value | Awaited<CallResult<T>> |
Returns
MockedFunction<T>mockResolvedValueOnce
mockResolvedValueOnce(value: Awaited<CallResult<T>>): MockedFunction<T>Resolves the next call only to value.
Parameters
| Name | Type | Description |
|---|---|---|
value | Awaited<CallResult<T>> |
Returns
MockedFunction<T>mockRejectedValue
mockRejectedValue(value: unknown): MockedFunction<T>Rejects every call with value.
Parameters
| Name | Type | Description |
|---|---|---|
value | unknown |
Returns
MockedFunction<T>mockRejectedValueOnce
mockRejectedValueOnce(value: unknown): MockedFunction<T>Rejects the next call only with value.
Parameters
| Name | Type | Description |
|---|---|---|
value | unknown |
Returns
MockedFunction<T>mockImplementation
mockImplementation(fn: Implementation<T>): MockedFunction<T>Runs fn for every call.
Parameters
| Name | Type | Description |
|---|---|---|
fn | Implementation<T> |
Returns
MockedFunction<T>mockImplementationOnce
mockImplementationOnce(fn: Implementation<T>): MockedFunction<T>Runs fn for the next call only; *Once implementations run in the order they were set.
Parameters
| Name | Type | Description |
|---|---|---|
fn | Implementation<T> |
Returns
MockedFunction<T>mockClear
mockClear(): MockedFunction<T>Forgets the recorded calls, keeping the implementation.
Returns
MockedFunction<T>mockReset
mockReset(): MockedFunction<T>Forgets the recorded calls, and puts back the implementation the mock was created with.
Returns
MockedFunction<T>mockRestore
mockRestore(): MockedFunction<T>Does what mockReset does: a mock from meocord/testing replaces no original to restore.
Returns
MockedFunction<T>getMockName
getMockName(): stringThe name the mock reports in an assertion's message.
Returns
stringmockName
mockName(name: string): MockedFunction<T>Sets the name the mock reports in an assertion's message.
Parameters
| Name | Type | Description |
|---|---|---|
name | string |
Returns
MockedFunction<T>