diff --git a/src/testing-utils.ts b/src/testing-utils.ts index 2b188857a..4e8d17520 100644 --- a/src/testing-utils.ts +++ b/src/testing-utils.ts @@ -179,13 +179,25 @@ export function addSinonAssertions( ): ExecutionContext & AvaSinonAssertions { return { ...t, - onceWith: (stub, ...expected) => { - if (stub.callCount > 0) { - // Reduce the arguments of the first call to the same number that was provided, - // so that extra arguments don't lead to a failure. - return t.deepEqual(stub.args[0].slice(0, expected.length), expected); + onceWith: ( + stub: sinon.SinonStub, + ...expected: sinon.MatchPartialArguments + ) => { + // Fail if the stub hasn't been called at all so that we can safely compare + // the arguments of the first call in the else branch. + if (stub.callCount === 0) { + t.fail("The stub wasn't called."); } else { - return t.fail("The stub wasn't called."); + // Reduce the arguments of each to the same number that was provided, + // so that extra arguments don't lead to a failure. + const actual = stub.args.map>( + (args: TArgs) => + args.slice( + 0, + expected.length, + ) as sinon.MatchPartialArguments, + ); + return t.deepEqual(actual, [expected]); } }, };