2016-08-03 21:27:03 +02:00
|
|
|
/* eslint-env qunit */
|
2015-05-04 01:12:38 +02:00
|
|
|
import mergeOptions from '../../../src/js/utils/merge-options.js';
|
2013-12-03 04:03:32 +03:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
QUnit.module('merge-options');
|
2017-02-16 23:55:54 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should merge options objects', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const ob1 = {
|
2013-12-03 04:03:32 +03:00
|
|
|
a: true,
|
|
|
|
b: { b1: true, b2: true, b3: true },
|
|
|
|
c: true
|
|
|
|
};
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const ob2 = {
|
2013-12-03 04:03:32 +03:00
|
|
|
// override value
|
|
|
|
a: false,
|
|
|
|
// merge sub-option values
|
|
|
|
b: { b1: true, b2: false, b4: true },
|
|
|
|
// add new option
|
|
|
|
d: true
|
|
|
|
};
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const ob3 = mergeOptions(ob1, ob2);
|
2013-12-03 04:03:32 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.deepEqual(ob3, {
|
2013-12-03 04:03:32 +03:00
|
|
|
a: false,
|
|
|
|
b: { b1: true, b2: false, b3: true, b4: true },
|
|
|
|
c: true,
|
|
|
|
d: true
|
|
|
|
}, 'options objects merged correctly');
|
2015-03-11 03:01:11 +02:00
|
|
|
});
|
2017-02-16 23:55:54 +02:00
|
|
|
|
|
|
|
QUnit.test('should ignore non-objects', function(assert) {
|
|
|
|
const obj = { a: 1 };
|
|
|
|
|
|
|
|
assert.deepEqual(mergeOptions(obj, true), obj, 'ignored non-object input');
|
|
|
|
});
|