diff --git a/lib/utils.js b/lib/utils.js index 32a83c75..9095b9d1 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -41,7 +41,7 @@ exports.merge = function (target, source, options) { return target; } - if (typeof target !== 'object') { + if (!target || typeof target !== 'object') { return [target].concat(source); } diff --git a/test/utils.js b/test/utils.js index 67ef9369..3c7ee523 100644 --- a/test/utils.js +++ b/test/utils.js @@ -6,6 +6,8 @@ var utils = require('../lib/utils'); test('merge()', function (t) { t.deepEqual(utils.merge(null, true), [null, true], 'merges true into null'); + t.deepEqual(utils.merge(null, [42]), [null, 42], 'merges null into an array'); + t.deepEqual(utils.merge({ a: 'b' }, { a: 'c' }), { a: ['b', 'c'] }, 'merges two objects with the same key'); var oneMerged = utils.merge({ foo: 'bar' }, { foo: { first: '123' } });