fix(object): Update toHaveProperty matcher to support nested property paths using dot notation

This commit is contained in:
2025-04-30 18:00:29 +00:00
parent ef5770e41a
commit e7941e7b99
4 changed files with 30 additions and 4 deletions

View File

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

View File

@ -62,11 +62,16 @@ export class ObjectMatchers<T extends object, M extends TExecutionType> {
return this.assertion.customAssertion(
(v) => {
const obj = v as any;
if (!(property in obj)) {
return false;
const path = property.split('.');
let current = obj;
for (const key of path) {
if (current == null || !(key in current)) {
return false;
}
current = current[key];
}
if (arguments.length === 2) {
return plugins.fastDeepEqual(obj[property], value);
return plugins.fastDeepEqual(current, value);
}
return true;
},