Skip to main content

Function: when()

Call Signature

when<T>(method): MethodStubSetter<Promise<T>, T, Error>

Defined in: ts-mockito.ts:111

Starts stubbing a mocked async method call, allowing .thenResolve()/.thenReject() in addition to the regular stubbing behaviors.

Type Parameters

T

T

Parameters

method

Promise<T>

a call made on a mock that returns a Promise

Returns

MethodStubSetter<Promise<T>, T, Error>

a MethodStubSetter

Call Signature

when<T>(method): MethodStubSetter<T>

Defined in: ts-mockito.ts:123

Starts stubbing a mocked method call (or getter access) with a specific behavior.

Type Parameters

T

T

Parameters

method

T

a call made on a mock, e.g. mockedFoo.getBar(3), or a getter access, e.g. mockedFoo.sampleGetter

Returns

MethodStubSetter<T>

a MethodStubSetter with .thenReturn(), .thenThrow(), .thenCall(), etc.

Example

when(mockedFoo.getBar(3)).thenReturn('three');