Home > @wixc3/testing > waitForStubCall
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[];
}>;
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[]; }>
expect(await waitForStubCall(async (stub) => {
await sleep(1);
stub('success');
return 'action!';
})).to.eql({
callArgs: ['success'],
returned: 'action!',
});