diff --git a/__tests__/helpers.spec.js b/__tests__/helpers.spec.js index 745829c..6d8f086 100644 --- a/__tests__/helpers.spec.js +++ b/__tests__/helpers.spec.js @@ -24,6 +24,23 @@ describe('merge', () => { } }) }) + + it ('should merge objects containing non-objects', () => { + const a = { c: [ 1, 2, 3 ], d: Promise.resolve({ a: 1 }) } + const b = { c: [ 4, 5 ], d: { b: 1 } } + const c = helpers.merge(a, b) + + expect(c).toEqual({ + c: [ + 4, + 5, + 3 + ], + d: { + b: 1 + } + }) + }) }) describe('getMethod', () => { diff --git a/src/helpers.js b/src/helpers.js index 0a05fcf..fd9ef65 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -30,7 +30,9 @@ export function getBasePath (base, path) { export function merge (obj, src) { Object.keys(src).forEach(function (key) { - if (obj[key] && typeof obj[key] === 'object') { + const type = obj[key] && Object.prototype.toString.call(obj[key]) + + if (type === '[object Object]' || type === '[object Array]') { merge(obj[key], src[key]) return }