-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
test.js
38 lines (32 loc) · 1.05 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
'use strict';
require('mocha');
const assert = require('assert');
const union = require('./');
describe('union', () => {
it('should add a value:', () => {
let obj = {};
union(obj, 'foo', ['a', 'b'])
assert.deepEqual(obj.foo, ['a', 'b']);
});
it('should union a value:', () => {
let obj = {foo: ['a', 'b']};
union(obj, 'foo', ['c', 'd', 'e'])
assert.deepEqual(obj.foo, ['a', 'b', 'c', 'd', 'e']);
});
it('should union a deeply nested value:', () => {
let obj = {};
union(obj, 'a.b.c', ['one', 'two']);
union(obj, 'a.b.c', ['three']);
assert.deepEqual(obj.a.b.c, ['one', 'two', 'three']);
});
it('should support escaped dots:', () => {
let obj = {};
union(obj, 'a\\.b.c', ['one', 'two']);
union(obj, 'a\\.b.c', ['three']);
assert.deepEqual(obj['a.b'].c, ['one', 'two', 'three']);
});
it('should throw an error:', () => {
assert.throws(() => union(), /expected the first argument to be an object/);
assert.throws(() => union({}), /expected the second argument to be a string/);
});
});