smartexpect/test/test.diffOutput.ts

32 lines
1.1 KiB
TypeScript
Raw Normal View History

import { tap, expect as tExpect } from '@push.rocks/tapbundle';
import * as smartexpect from '../dist_ts/index.js';
tap.test('diff-like output for object.toEqual mismatch', async () => {
const a = { x: 1, y: 2 };
const b = { x: 1, y: 3 };
try {
smartexpect.expect(a).object.toEqual(b);
throw new Error('Assertion did not throw');
} catch (err: any) {
const msg: string = err.message;
tExpect(msg.includes('Expected objects to be deeply equal')).toBeTrue();
tExpect(msg.includes('Received:')).toBeTrue();
tExpect(msg.includes('"y": 2')).toBeTrue();
}
});
tap.test('diff-like output for array.toContainEqual mismatch', async () => {
const arr = [{ id: 1 }, { id: 2 }];
const item = { id: 3 };
try {
smartexpect.expect(arr).array.toContainEqual(item);
throw new Error('Assertion did not throw');
} catch (err: any) {
const msg: string = err.message;
tExpect(msg.includes('Expected array to contain equal to')).toBeTrue();
tExpect(msg.includes('Received:')).toBeTrue();
tExpect(msg.includes('"id": 1')).toBeTrue();
}
});
export default tap.start();