37 lines
996 B
JavaScript
37 lines
996 B
JavaScript
const compare = require('../src/compare');
|
|
|
|
describe('compare function', () => {
|
|
test('returns empty array when all objects are equal', () => {
|
|
const a = { x: 1, y: 2 };
|
|
const b = { x: 1, y: 2 };
|
|
const c = { x: 1, y: 2 };
|
|
expect(compare(a, b, c)).toEqual([]);
|
|
});
|
|
|
|
test('detects differences in top-level keys', () => {
|
|
const a = { x: 1, y: 2 };
|
|
const b = { x: 1, y: 3 };
|
|
const c = { x: 1, y: 2 };
|
|
expect(compare(a, b, c)).toEqual([
|
|
{ key: 'y', values: [2, 3, 2] },
|
|
]);
|
|
});
|
|
|
|
test('detects differences in nested objects', () => {
|
|
const a = { a: { b: 1 } };
|
|
const b = { a: { b: 2 } };
|
|
const c = { a: { b: 1 } };
|
|
expect(compare(a, b, c)).toEqual([
|
|
{ key: 'a.b', values: [1, 2, 1] },
|
|
]);
|
|
});
|
|
|
|
test('handles missing keys', () => {
|
|
const a = { x: 1 };
|
|
const b = { x: 1, y: 2 };
|
|
const c = { x: 1 };
|
|
expect(compare(a, b, c)).toEqual([
|
|
{ key: 'y', values: [undefined, 2, undefined] },
|
|
]);
|
|
});
|
|
}); |