UNPKG

1.08 kBPlain TextView Raw
1import diff from '../util/diff';
2
3describe('diff', () => {
4 it('Should return no differences', () => {
5 const obj1 = {
6 key1: 0
7 };
8
9 const obj2 = {
10 key1: 0
11 };
12
13 const res = diff(obj1, obj2);
14
15 expect(res).toEqual({});
16 });
17
18 it('Should return one difference', () => {
19 const obj1 = {
20 key1: 0
21 };
22
23 const obj2 = {
24 key1: 1
25 };
26
27 const res = diff(obj1, obj2);
28
29 expect(res).toEqual({ key1: 1 });
30 });
31
32 it('Should return 1 removed key', () => {
33 const obj1 = {
34 key1: 0
35 };
36
37 const obj2 = {};
38
39 const res = diff(obj1, obj2);
40
41 expect(res).toEqual({ key1: undefined });
42 });
43
44 it('Should return 1 added key', () => {
45 const obj1 = {};
46
47 const obj2 = {
48 key1: 0
49 };
50
51 const res = diff(obj1, obj2);
52
53 expect(res).toEqual({ key1: 0 });
54 });
55
56 it('Should return 1 removed and 1 added key', () => {
57 const obj1 = {
58 key1: 0
59 };
60
61 const obj2 = {
62 key2: 0
63 };
64
65 const res = diff(obj1, obj2);
66
67 expect(res).toEqual({ key1: undefined, key2: 0 });
68 });
69});