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

14
test/test.propertyPath.ts Normal file
View File

@ -0,0 +1,14 @@
import { tap, expect as tExpect } from '@push.rocks/tapbundle';
import * as smartexpect from '../dist_ts/index.js';
tap.test('toHaveProperty nested path via dot notation', async () => {
const testObject = { level1: { level2: { level3: 'value' } } };
// Existence check
smartexpect.expect(testObject).object.toHaveProperty('level1.level2.level3');
// Value check
smartexpect.expect(testObject).object.toHaveProperty('level1.level2.level3', 'value');
// Negation for missing deep property
smartexpect.expect(testObject).not.object.toHaveProperty('level1.level2.missing');
});
export default tap.start();