forked from mrmurphy/omit-deep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
62 lines (51 loc) · 1.81 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
'use strict';
var should = require('should');
var omitDeep = require('./');
describe('.omit()', function () {
it('should recursively omit key passed as a string.', function () {
var o = omitDeep({a: 'a', b: 'b', c: {b: 'b', d: 'd', e: {b: 'b', f: 'f', g: {b: 'b', c: 'c'}}}}, 'b')
o.should.eql({a: 'a', c: {d: 'd', e: {f: 'f', g: {c: 'c'}}}});
});
it('should recursively omit key passed as an array.', function () {
var o = omitDeep({a: 'a', b: 'b', c: {b: 'b', d: 'd', e: {b: 'b', f: 'f', g: {b: 'b', c: 'c'}}}}, ['b'])
o.should.eql({a: 'a', c: {d: 'd', e: {f: 'f', g: {c: 'c'}}}});
});
it('should recursively omit multiple keys.', function () {
var o = omitDeep({a: 'a', b: 'b', c: {b: 'b', d: 'd', e: {b: 'b', f: 'f', g: {b: 'b', c: 'c'}}}}, ['b', 'd', 'f'])
o.should.eql({a: 'a', c: {e: {g: {c: 'c'}}}});
});
it('should omit the given keys.', function () {
omitDeep({a: 'a', b: 'b', c: 'c'}, ['a', 'c']).should.eql({ b: 'b' });
});
it('should return the object if no keys are specified.', function () {
omitDeep({a: 'a', b: 'b', c: 'c'}).should.eql({a: 'a', b: 'b', c: 'c'});
});
it('should return an empty object if no object is specified.', function () {
omitDeep().should.eql({});
});
it('should return the input unchaged if not an array or an object', function () {
omitDeep('foo').should.eql('foo');
});
it('should omit keys from objects in arrays', function () {
var o = omitDeep([
{a: 'a', b: 'b'},
[
{a: 'a', b: 'b'}
]
], 'b')
o.should.eql([
{a: 'a'},
[
{a: 'a'}
]
]);
});
it('should preserve arrays when not omitting objects from them', function() {
var o = omitDeep({
"numbers": ["1", "2"]
}, 'nothing')
o.should.eql({
"numbers": ["1", "2"]
});
})
});