feat(core): Add new matchers and improve negation messaging
This commit is contained in:
32
test/test.diffOutput.ts
Normal file
32
test/test.diffOutput.ts
Normal file
@ -0,0 +1,32 @@
|
||||
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();
|
Reference in New Issue
Block a user