Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.js 1.4KB

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. var test = require('tape');
  3. var utils = require('../lib/utils');
  4. test('merge()', function (t) {
  5. t.deepEqual(utils.merge({ a: 'b' }, { a: 'c' }), { a: ['b', 'c'] }, 'merges two objects with the same key');
  6. var oneMerged = utils.merge({ foo: 'bar' }, { foo: { first: '123' } });
  7. t.deepEqual(oneMerged, { foo: ['bar', { first: '123' }] }, 'merges a standalone and an object into an array');
  8. var twoMerged = utils.merge({ foo: ['bar', { first: '123' }] }, { foo: { second: '456' } });
  9. t.deepEqual(twoMerged, { foo: { 0: 'bar', 1: { first: '123' }, second: '456' } }, 'merges a standalone and two objects into an array');
  10. var sandwiched = utils.merge({ foo: ['bar', { first: '123', second: '456' }] }, { foo: 'baz' });
  11. t.deepEqual(sandwiched, { foo: ['bar', { first: '123', second: '456' }, 'baz'] }, 'merges an object sandwiched by two standalones into an array');
  12. var nestedArrays = utils.merge({ foo: ['baz'] }, { foo: ['bar', 'xyzzy'] });
  13. t.deepEqual(nestedArrays, { foo: ['baz', 'bar', 'xyzzy'] });
  14. t.end();
  15. });
  16. test('assign()', function (t) {
  17. var target = { a: 1, b: 2 };
  18. var source = { b: 3, c: 4 };
  19. var result = utils.assign(target, source);
  20. t.equal(result, target, 'returns the target');
  21. t.deepEqual(target, { a: 1, b: 3, c: 4 }, 'target and source are merged');
  22. t.deepEqual(source, { b: 3, c: 4 }, 'source is untouched');
  23. t.end();
  24. });