-
Notifications
You must be signed in to change notification settings - Fork 13
/
test.js
81 lines (65 loc) · 1.3 KB
/
test.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
var diff = require('./');
var test = require('tape');
test(function( t ) {
var a = {
speed: 4,
power: 54,
height: undefined,
level: 1,
};
var b = {
speed: 4, // unchanged
power: 22, // changed
level: undefined, // changed
weight: 10, // added
};
t.deepEqual(diff(a, b), {
power: 22,
level: undefined,
weight: 10,
});
var c = {
speed: 5, // changed
power: 54, // unchanged
level: 100, // changed
material: 'steel', // added
location: undefined, // added but undefined
};
t.deepEqual(diff(a, b, c), {
speed: 5,
power: 22,
level: 100,
weight: 10,
material: 'steel',
});
t.deepEqual(diff({}, {}), {});
t.end();
});
test('Custom equality', function( t ) {
var created = '2016-04-24T10:39:23.419Z';
var now = new Date();
var a = {
created: new Date(created),
updated: new Date(created),
};
var b = {
created: new Date(created), // unchanged
updated: now, // changed
};
t.deepEqual(diff(a, b), {
created: new Date(created),
updated: now,
}, 'expected default behavior');
t.deepEqual(diff.custom({
equal: dateAwareComparator,
}, a, b), {
updated: now,
});
t.end();
});
function dateAwareComparator( a, b ){
if (a instanceof Date && b instanceof Date)
return a.getTime() === b.getTime();
return a === b;
}