Skip to content

Commit

Permalink
fix: concat with lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
vonagam committed Feb 6, 2019
1 parent 2e87196 commit e250193
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const proto = (SchemaType.prototype = {
},

concat(schema) {
if (!schema) return this;
if (!schema || schema === this) return this;

if (schema._type !== this._type && this._type !== 'mixed')
throw new TypeError(
Expand Down
2 changes: 2 additions & 0 deletions src/util/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export default function merge(target, source) {

if (sourceVal === undefined) {
source[key] = targetVal;
} else if (sourceVal === targetVal) {
continue;
} else if (isSchema(sourceVal)) {
if (isSchema(targetVal)) source[key] = targetVal.concat(sourceVal);
} else if (isObject(sourceVal)) {
Expand Down
11 changes: 11 additions & 0 deletions test/yup.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ describe('Yup', function() {
});
});

it('should not merge needlesly', function() {
var schema = string();
var spy = sinon.spy(schema, 'concat');
var a = { schema };
var b = { schema };
var c = merge(a, b);

c.schema.should.equal(schema);
spy.should.not.have.been.called();
});

it('should getIn correctly', async () => {
var num = number(),
inst = object().shape({
Expand Down

0 comments on commit e250193

Please sign in to comment.