-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
170 lines (161 loc) · 4.4 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
'use strict';
var chai = require('chai'),
getDeep = require('./index'),
// examples
in1 = {
en: 'The title',
fr: 'Le title'
},
out1 = 'The title',
in2 = {
title: {
en: 'The title',
fr: 'Le title'
}
},
out2 = {
title: 'The title'
},
in3 = [
{
en: 'item 1',
fr: 'Le item 1'
},
{
en: 'item 2',
fr: 'Le item 2'
}
],
out3 = [
'item 1',
'item 2'
],
in4 = {
title: {
en: 'the title',
fr: 'Le title'
},
body: {
en: 'the body',
fr: 'Le body'
},
children: [
{
title: {
en: 'child 1',
fr: 'Le child 1'
},
body: {
en: 'the child body',
fr: 'Le child body'
},
children: [
{
title: {
en: 'item 1',
fr: 'Le item 1'
},
body: {
en: 'the body goes here',
fr: 'le body french'
}
},
{
title: {
en: 'item 2',
fr: 'Le item 2'
},
body: {
en: 'some more body',
fr: 'le body french more'
}
}
]
},
{
title: {
en: 'child 2',
fr: 'Le child 2'
},
body: {
en: 'the child body',
fr: 'Le child body'
},
children: [
{
title: {
en: 'child item 1',
fr: 'Le item 1'
},
body: {
en: 'the child body goes here',
fr: 'le body french'
}
},
{
title: {
en: 'child item 2',
fr: 'Le item 2'
},
body: {
en: 'some more child body',
fr: 'le body french more'
}
}
]
}
]
},
out4 = {
title: 'the title',
body: 'the body',
children: [
{
title: 'child 1',
body: 'the child body',
children: [
{
title: 'item 1',
body: 'the body goes here'
},
{
title: 'item 2',
body: 'some more body'
}
]
},
{
title: 'child 2',
body: 'the child body',
children: [
{
title: 'child item 1',
body: 'the child body goes here'
},
{
title: 'child item 2',
body: 'some more child body'
}
]
}
]
};
chai.should();
describe('getDeep', function() {
it('should get object property', function() {
getDeep('en', in1).should.deep.equal(out1);
});
it('should get object[prop][key] on each prop of object that is type object', function() {
getDeep('en', in2).should.deep.equal(out2);
});
it('should work on arrays', function() {
getDeep('en', in3).should.deep.equal(out3);
});
it('should work on nested objects and arrays', function() {
getDeep('en', in4).should.deep.equal(out4);
});
it('should not modify the input', function() {
Object.freeze(in4);
chai.expect(getDeep.bind(null, 'en', in4)).to.not.throw();
})
});