UNPKG

1.67 kBJavaScriptView Raw
1const objectDiff = require('./object-diff')
2
3describe('objectDiff', () => {
4 test('basic objects', () => {
5 expect(
6 objectDiff(
7 {
8 a: 1,
9 b: 2,
10 c: 3,
11 d: { 5: 6 },
12 e: [true, false]
13 },
14 {
15 b: 2,
16 c: 4,
17 d: 5,
18 e: [true, false] // ditto
19 }
20 )
21 ).toEqual({
22 c: 4,
23 d: 5,
24 e: [true, false]
25 // again, if there's a "diff" in array the whole thing's going on the list because idgaf
26 })
27 })
28
29 test('missing properties', () => {
30 expect(objectDiff({ a: 1 }, { a: 1, b: 2 })).toEqual({ b: 2 })
31 expect(objectDiff({ a: 1 }, { a: 1, b: { c: 'd' } })).toEqual({
32 b: { c: 'd' }
33 })
34 })
35
36 test('nested objects', () => {
37 expect(
38 objectDiff(
39 {
40 a: {
41 a1: {
42 a11: {
43 b: 'c',
44 d: { e: 'f' }
45 },
46 a12: [1, 2, 3]
47 },
48 a2: false
49 },
50 b: 1,
51 c: 2
52 },
53 {
54 a: {
55 a1: {
56 a11: {
57 b: 'c',
58 d: 'e'
59 },
60 a12: [1, 2, 3]
61 },
62 a2: false
63 },
64 b: 1,
65 c: '2'
66 }
67 )
68 ).toEqual({
69 a: {
70 a1: {
71 a11: {
72 d: 'e'
73 },
74 a12: [1, 2, 3]
75 }
76 },
77 c: '2'
78 })
79 })
80
81 test('dates', () => {
82 expect(
83 objectDiff(
84 { date: new Date('1984-04-07') },
85 { date: new Date('1984-04-07').toISOString() }
86 )
87 ).toEqual({})
88 })
89})