-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
40 lines (34 loc) · 985 Bytes
/
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
var assert = require('assert');
var chain = require('./index');
var testObj = {
code: 200,
data: {
list: [
{ id: 1, name: 'name1' },
{ id: 2, name: 'name2' }
],
page: {
current: 1,
total: 200
}
}
};
describe('explicit path', function() {
it('should return 200 with path: \'.code\'', function() {
assert.equal(200, chain(testObj, '.code'));
});
it('should return 1 with path: \'.data.page.current\'', function() {
assert.equal(1, chain(testObj, '.data.page.current'));
});
it('should return 1 with path: \'.data.list[0].id\'', function() {
assert.equal(1, chain(testObj, '.data.list[0].id'));
});
});
describe('wrong path', function() {
it('should return undefined with path: \'.wrong.path\'', function() {
assert.equal(undefined, chain(testObj, '.wrong.path'));
});
it('should return 666 with path: \'.wrong.path\'', function() {
assert.equal(666, chain(testObj, '.wrong.path', 666));
});
});