fix(assertion-matchers): Refactor matcher implementations to consistently use customAssertion for improved consistency and clarity.
This commit is contained in:
@ -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}` : ''}`
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user