diff --git a/index.js b/index.js index 0ed4800..df7c1e7 100644 --- a/index.js +++ b/index.js @@ -41,7 +41,11 @@ module.exports = class Conf { merge (obj) { return _.mergeWith(this.config, obj, (configValue, overrideValue) => { // Do not apply merge on non-plain objects - if (typeof overrideValue === 'object' && overrideValue.constructor !== Object) { + if ( + overrideValue && + typeof overrideValue === 'object' && + overrideValue.constructor !== Object + ) { return overrideValue } diff --git a/test/unit/conf_tests.js b/test/unit/conf_tests.js index 3da000a..0e02fb5 100644 --- a/test/unit/conf_tests.js +++ b/test/unit/conf_tests.js @@ -162,6 +162,13 @@ describe('The Conf', () => { expect(config.get('foo')).to.deep.equal(['quz']) }) + it('merges null', function () { + const config = new Conf({foo: ['foo', 'bar']}) + + config.merge({foo: null}) + expect(config.config.foo).to.deep.equal(null) + }) + it('does not merge class instances, keeps the original object', function () { class Foo { constructor () {