object.js
1.19 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
/**
* Module dependencies.
*/
var object = require('..');
describe('.keys(obj)', function(){
it('should return the keys of an object', function(){
var obj = { name: 'tobi', age: 1 };
object.keys(obj).should.eql(['name', 'age']);
})
})
describe('.values(obj)', function(){
it('should return the values of an object', function(){
var obj = { name: 'tobi', age: 1 };
object.values(obj).should.eql(['tobi', 1]);
})
})
describe('.length(obj)', function(){
it('should return key count', function(){
var obj = { name: 'tobi', age: 1 };
object.length(obj).should.equal(2);
})
})
describe('.merge(a, b)', function(){
it('should merge two objects', function(){
var a = { foo: 'bar' };
var b = { bar: 'baz' };
object.merge(a, b).should.eql({ foo: 'bar', bar: 'baz' });
})
it('should give precedence to b', function(){
var a = { foo: 'bar' };
var b = { foo: 'baz' };
object.merge(a, b).should.eql({ foo: 'baz' });
})
})
describe('.isEmpty()', function(){
it('should check if the object is empty', function(){
object.isEmpty({}).should.be.true;
object.isEmpty({ foo: 'bar' }).should.be.false;
})
})