Skip to content

Commit

Permalink
Fix bug where non-instances were attempted to be merged as instances
Browse files Browse the repository at this point in the history
  • Loading branch information
JaapRood committed May 3, 2018
1 parent 2ed779d commit e195336
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ internals.mergeDeep = function(state, data) {
if (Schema.isType(definition)) {
let type = definition

if (!_isFunction(type.mergeDeep)) {
if (
!_isFunction(type.mergeDeep) ||
_isFunction(type.instanceOf) && !Schema.instanceOfType(type, currentValue)
) {
return nextValue
} else {
return type.mergeDeep(currentValue, nextValue)
Expand Down
2 changes: 1 addition & 1 deletion test/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ Test('model.mergeDeep', function(t) {
t.equal(merged.get('a'), outputA, 'value returned by mergeDeep of schema is used as value')
t.equal(merged.getIn(['nested', 'b']), outputB, 'nested schema is applied to nested attributes')
t.ok(OtherModel.instanceOf(merged.get('nestedModel')), 'Model definitions are valid type definitions for merging deep')
t.equal(merged.get('notInstance'), outputA, 'mergeDeep of schema definition is still applied when schema has instanceOf method that returns falsey')
t.equal(merged.get('notInstance'), inputA, 'next value is returned when definition schema has instanceOf method that returns falsey for existing value')

t.ok(Immutable.List([outputA, outputB]).equals(merged.get('nestedList')), 'schema generated with `Schema.listOf` return only the new values as Lists merging is ambiguous')
t.ok(Immutable.Set([outputA, outputB]).equals(merged.get('nestedSet')), 'schema generated with `Schema.setOf` return only then new values as Sets merging is ambiguous')
Expand Down

0 comments on commit e195336

Please sign in to comment.