8000 fix(utils): deepMixIn to properly merge undefined values of source by ivanvoznyakovsky · Pull Request #502 · js-data/js-data · GitHub
[go: up one dir, main page]

Skip to content

fix(utils): deepMixIn to properly merge undefined values of source #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ const utils = {
const existing = dest[key]
if (isPlainObject(value) && isPlainObject(existing)) {
utils.deepMixIn(existing, value)
} else {
} else if (existing === undefined || value !== undefined) {
dest[key] = value
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/unit/utils/extendUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ describe('utils.deepMixIn', function () {
assert.deepEqual(expected, actual, 'sorce own properties recursivly copied and overriden into dest')
assert.equal(dest, utils.deepMixIn(dest), 'empty source argument returns dest')
})

it('skips source properties that resolve to undefined if a destination value exists', function () {
const dest = { name: 'John', age: 90 }
const src = { name: 'John', age: undefined }
const expected = { name: 'John', age: 90 }
const actual = utils.deepMixIn(dest, src)

assert.deepEqual(expected, actual)
})
})

describe('utils.extend', function () {
Expand Down
0