fix(object): Update toHaveProperty matcher to support nested property paths using dot notation
This commit is contained in:
@ -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.'
|
||||
}
|
||||
|
@ -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;
|
||||
},
|
||||
|
Reference in New Issue
Block a user