mirror of
https://github.com/github/codeql-action
synced 2026-10-07 00:30:17 +03:00
Add utility for assertions on sinon stubs with better output by default
This commit is contained in:
@@ -163,6 +163,34 @@ export function setupTests(testFn: TestFn<any>) {
|
||||
});
|
||||
}
|
||||
|
||||
export interface AvaSinonAssertions {
|
||||
/**
|
||||
* Asserts that `stub` must have been called once with at least the `expected` arguments.
|
||||
*/
|
||||
onceWith: <TArgs extends readonly any[]>(
|
||||
stub: sinon.SinonStub<TArgs>,
|
||||
...expected: sinon.MatchPartialArguments<TArgs>
|
||||
) => boolean;
|
||||
}
|
||||
|
||||
/** Adds additional assertions for use with `sinon` to `t`. */
|
||||
export function addSinonAssertions(
|
||||
t: ExecutionContext<unknown>,
|
||||
): ExecutionContext<unknown> & 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);
|
||||
} else {
|
||||
return t.fail("The stub wasn't called.");
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare a reusable test implementation, with better type safety than `test.macro`.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user