File: test.js

package info (click to toggle)
node-union-value 2.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112 kB
  • sloc: makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,073 bytes parent folder | download | duplicates (3)
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/);
  });
});