-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
82 lines (64 loc) · 1.95 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
describe('propget', function () {
'use strict';
var propget = require('./')
, assume = require('assume');
it('is exported as function', function () {
assume(propget).is.a('function');
});
it('can find item in array using dot notation', function () {
var data = { foo: ['bar', 'baz'] };
assume(propget(data, 'foo.1')).equals('baz');
assume(propget(data, 'foo.3')).equals(undefined);
});
it('can find deeply nested object', function () {
var data = { foo: {'bar': 'baz'} };
assume(propget(data, 'foo.bar')).equals('baz');
assume(propget(data, 'foo.lol')).equals(undefined);
});
it('does not worry about undefined keys', function () {
var data = {};
assume(propget(data, 'foo.bar.l1.4.0.afa')).equals(undefined);
});
it('can find keys that have dot notation', function () {
var data = { 'foo.bar': 'lol' };
assume(propget(data, 'foo.bar')).equals('lol');
});
describe('function execution', function () {
it('can execute a function using dot notation', function () {
var data = {
foo: {
bar: function () {
return 'baz';
}
}
};
assume(propget(data, 'foo.bar()')).equals('baz');
});
it('can execute a function with arguments using dot notation', function (next) {
next = assume.plan(3, next);
var data = {
foo: {
bar: function (arg1, arg2) {
assume(arg1).equals('he');
assume(arg2).equals('hoo');
return 'baz';
}
}
};
assume(propget(data, 'foo.bar(first, second)', 'he', 'hoo')).equals('baz');
next();
});
it('can continue searching the returned object from function call', function () {
var data = {
foo: {
bar: function () {
return {
what: 'lol'
}
}
}
};
assume(propget(data, 'foo.bar().what')).equals('lol');
});
});
});