fix(assertion-matchers): Refactor matcher implementations to consistently use customAssertion for improved consistency and clarity.

This commit is contained in:
2025-04-28 19:58:32 +00:00
parent 4eac4544a5
commit 91a3dc43d3
11 changed files with 265 additions and 43 deletions

View File

@ -7,6 +7,23 @@ export class FunctionMatchers {
constructor(private assertion: Assertion<Function>) {}
toThrow(expectedError?: any) {
return this.assertion.toThrow(expectedError);
return this.assertion.customAssertion(
(value) => {
let threw = false;
try {
(value as Function)();
} catch (e: any) {
threw = true;
if (expectedError) {
if (typeof expectedError === 'function') {
return e instanceof expectedError;
}
return e === expectedError;
}
}
return threw;
},
`Expected function to throw${expectedError ? ` ${expectedError}` : ''}`
);
}
}