-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.js
More file actions
54 lines (48 loc) · 1.48 KB
/
objects.js
File metadata and controls
54 lines (48 loc) · 1.48 KB
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
describe('utils objects', function () {
var Objects = require('../../src/js/utils/objects')
it('isEmpty', function () {
var isEmpty = Objects.isEmpty
isEmpty(null).should.be.true
isEmpty(undefined).should.be.true
isEmpty(NaN).should.be.true
isEmpty('').should.be.true
isEmpty([]).should.be.true
isEmpty({}).should.be.true
isEmpty(0).should.be.false
isEmpty(' ').should.be.false
isEmpty([1]).should.be.false
isEmpty({a:1}).should.be.false
isEmpty(new Date()).should.be.false
})
it('forEach', function () {
var obj = {a: 1, b: 2, c: 3},
keys = [],
value = 0
Objects.forEach(obj, function (v, k) {
keys.push(k)
value += v
})
keys.length.should.equal(3)
keys.should.deep.equal(['a','b','c'])
value.should.equal(6)
})
it('toTextValue', function () {
var _ = Objects.toTextValue
var arr = [1, 2, 3, 4]
var arrObj = arr.map(function (i) {
return { $text: i, $value: i }
})
_(arr).should.deep.equal(arrObj)
var rawObj = [
{ cn: '南京', key: 'nanjing' },
{ cn: '北京', key: 'beijing' },
{ cn: '上海', key: 'shanghai' }
]
var targetObj = [
{ cn: '南京', key: 'nanjing', $text: '南京', $value: 'nanjing' },
{ cn: '北京', key: 'beijing', $text: '北京', $value: 'beijing' },
{ cn: '上海', key: 'shanghai', $text: '上海', $value: 'shanghai' }
]
_(rawObj, '{cn}', '{key}').should.deep.equal(targetObj)
})
})