Skip to content

Commit 5d0dcf5

Browse files
committed
fix: Fix null merging
1 parent 0f32689 commit 5d0dcf5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ module.exports = class Conf {
4141
merge (obj) {
4242
return _.mergeWith(this.config, obj, (configValue, overrideValue) => {
4343
// Do not apply merge on non-plain objects
44-
if (typeof overrideValue === 'object' && overrideValue.constructor !== Object) {
44+
if (
45+
overrideValue &&
46+
typeof overrideValue === 'object' &&
47+
overrideValue.constructor !== Object
48+
) {
4549
return overrideValue
4650
}
4751

test/unit/conf_tests.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ describe('The Conf', () => {
162162
expect(config.get('foo')).to.deep.equal(['quz'])
163163
})
164164

165+
it('merges null', function () {
166+
const config = new Conf({foo: ['foo', 'bar']})
167+
168+
config.merge({foo: null})
169+
expect(config.config.foo).to.deep.equal(null)
170+
})
171+
165172
it('does not merge class instances, keeps the original object', function () {
166173
class Foo {
167174
constructor () {

0 commit comments

Comments
 (0)