smartexpect/test/test.propertypath.ts

18 lines
770 B
TypeScript
Raw Normal View History

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' }}, publicTest: 'hi' };
smartexpect.expect(testObject).object.toHaveProperty('publicTest');
smartexpect.expect(testObject).toHaveProperty('publicTest');
// 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();