Skip to content

Commit

Permalink
fix: Fix null merging
Browse files Browse the repository at this point in the history
  • Loading branch information
marcbachmann committed Jul 11, 2023
1 parent 0f32689 commit 5d0dcf5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 7 additions & 0 deletions test/unit/conf_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 5d0dcf5

Please sign in to comment.