fix(object): Update toHaveProperty matcher to support nested property paths using dot notation
This commit is contained in:
14
test/test.propertyPath.ts
Normal file
14
test/test.propertyPath.ts
Normal 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();
|
Reference in New Issue
Block a user