| 16 | */ |
| 17 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 18 | export function expectCall<TArgs extends any[] = any[], TReturnValue = any>( |
| 19 | stub: sinon.SinonStub<TArgs, TReturnValue>, |
| 20 | options: {fakeFn?: (...args: TArgs) => TReturnValue, callCount?: number} = {}): Promise<TArgs> { |
| 21 | return new Promise<TArgs>(resolve => { |
| 22 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 23 | stub.callsFake(function(this: any, ...args: TArgs) { |
| 24 | if (stub.callCount >= (options.callCount ?? 1)) { |
| 25 | resolve(args); |
| 26 | } |
| 27 | return (options.fakeFn ? options.fakeFn.apply(this, args) : undefined) as TReturnValue; |
| 28 | }); |
| 29 | }); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Returns a Promise that resolves with the arguments of the `stub`'s call once |