fix(Assertion): Improve toHaveProperty alias by forwarding arguments correctly for intuitive object property assertions

This commit is contained in:
2025-04-30 19:37:19 +00:00
parent 62cf7f5db5
commit ff795f6fe0
9 changed files with 76 additions and 2 deletions

View File

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

View File

@ -355,7 +355,13 @@ export class Assertion<T = unknown, M extends TExecutionType = 'sync'> {
public toInclude(substring: string) { return this.string.toInclude(substring); }
public toMatch(regex: RegExp) { return this.string.toMatch(regex); }
public toBeOneOf(values: any[]) { return this.string.toBeOneOf(values as string[]); }
public toHaveProperty(property: string, value?: any) { return this.object.toHaveProperty(property, value); }
public toHaveProperty(property: string, value?: any) {
// Forward only provided arguments to object matcher to preserve argument count
if (arguments.length === 2) {
return this.object.toHaveProperty(property, value);
}
return this.object.toHaveProperty(property);
}
public toHaveOwnProperty(property: string, value?: any) { return this.object.toHaveOwnProperty(property, value); }
public toMatchObject(expected: object) { return this.object.toMatchObject(expected); }
public toBeInstanceOf(constructor: any) { return this.object.toBeInstanceOf(constructor); }