-
Notifications
You must be signed in to change notification settings - Fork 3k
/
componentUpdater.spec.js
67 lines (51 loc) Β· 2.56 KB
/
componentUpdater.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {shouldUpdate} from './componentUpdater';
describe('component updater', () => {
it('should return true if two different objects are provided with same path', async () => {
const a = {details: 'whoa'};
const b = {details: 'whoax'};
const paths = ['details'];
expect(shouldUpdate(a, b, paths)).toEqual(true);
});
it('should return false if two same objects are provided with same path', async () => {
const a = {details: 'whoa'};
const b = {details: 'whoa'};
const paths = ['details'];
expect(shouldUpdate(a, b, paths)).toEqual(false);
});
it('should return true if two different deep objects are provided with same path', async () => {
const a = {details: {x: {y: 1}}};
const b = {details: {x: {y: 2}}};
const paths = ['details'];
expect(shouldUpdate(a, b, paths)).toEqual(true);
});
it('should return false if two same deep objects are provided with same path', async () => {
const a = {details: {x: {y: 1}}};
const b = {details: {x: {y: 1}}};
const paths = ['details'];
expect(shouldUpdate(a, b, paths)).toEqual(false);
});
it('should return false if several same deep objects are provided with same path', async () => {
const a = {details: {x: {y: 1}}, details2: {x: {y: 2}}, porage: 'yes'};
const b = {details: {x: {y: 1}}, details2: {x: {y: 2}}, porage: 'yes'};
const paths = ['details', 'details2', 'porage'];
expect(shouldUpdate(a, b, paths)).toEqual(false);
});
it('should return true if several different deep objects are provided with same path', async () => {
const a = {details: {x: {y: 1}}, details2: {x: {y: 2}}, porage: 'yes'};
const b = {details: {x: {y: 1}}, details2: {x: {y: 2}}, porage: 'no'};
const paths = ['details', 'details2', 'porage'];
expect(shouldUpdate(a, b, paths)).toEqual(true);
});
it('should return true if two different deep props of objects are provided with same path', async () => {
const a = {details: {x: {y: 1}}, details2: {x: {y: 2}}, porage: 'yes'};
const b = {details: {x: {y: 2}}, details2: {x: {y: 2}}, porage: 'yes'};
const paths = ['details.x.y', 'details2', 'porage'];
expect(shouldUpdate(a, b, paths)).toEqual(true);
});
it('should return false if two same deep props of objects are provided with same path', async () => {
const a = {details: {x: {y: 1}, y: '1'}, details2: {x: {y: 2}}, porage: 'yes'};
const b = {details: {x: {y: 1}}, details2: {x: {y: 2}}, porage: 'yes'};
const paths = ['details.x.y', 'details2', 'porage'];
expect(shouldUpdate(a, b, paths)).toEqual(false);
});
});