core3-utils

@wixc3/testing on Github

Home > @wixc3/testing > waitForStubCall

waitForStubCall() function

Creates a stub, then waits for it to be called

Signature:

export declare function waitForStubCall<T>(action: (stub: Stub) => T, waitForAction?: boolean): PromiseWithTimeout<{
    returned: T;
    callArgs: any[];
}>;

Parameters

Parameter Type Description
action (stub: [Stub](/core3-utils/testing.stub.html)) => T
waitForAction boolean _(Optional)_ when false the action is not awaited, waits only for the stub to be called

Returns:

PromiseWithTimeout<{ returned: T; callArgs: any[]; }>

Example

 expect(await waitForStubCall(async (stub) => {
     await sleep(1);
     stub('success');
     return 'action!';
 })).to.eql({
     callArgs: ['success'],
     returned: 'action!',
 });