feat(Assertion): Add toBeTypeOf assertion method

This commit is contained in:
2025-03-04 12:07:37 +00:00
parent 7ae5b4378a
commit e688207d23
5 changed files with 1532 additions and 1268 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartexpect',
version: '1.4.0',
version: '1.5.0',
description: 'A testing library to manage expectations in code, offering both synchronous and asynchronous assertion methods.'
}

View File

@ -209,6 +209,20 @@ export class Assertion {
});
}
public toBeTypeOf(expectedType: string) {
return this.runCheck(() => {
const actualType = typeof this.getObjectToTestReference();
if (actualType !== expectedType) {
throw new Error(
this.failMessage ||
`Assertion failed: ${this.baseReference} with drill down ${
this.propertyDrillDown
} is not of type ${expectedType}, but typeof ${actualType}`
);
}
});
}
public toHaveProperty(propertyArg: string, equalsArg?: any) {
return this.runCheck(() => {
const obj = this.getObjectToTestReference();