From 08a86c5b9eb59a66d2a15eb5511bebefa7a3c836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cemalettin=20Ta=C5=9F?= Date: Sun, 13 Dec 2020 22:14:15 +0300 Subject: [PATCH 1/2] fix(schema): Don't initialize spec values with undefined (jquense/yup#1160) Concatting schemas can overwrite previous non-undefined values with undefined --- src/schema.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/schema.ts b/src/schema.ts index 7ffaccd91..d80d1d841 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -137,8 +137,6 @@ export default abstract class BaseSchema< strict: false, abortEarly: true, recursive: true, - label: undefined, - meta: undefined, nullable: false, presence: 'optional', ...options?.spec, From 2af94177cbd147710a94335006abad2574a24f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cemalettin=20Ta=C5=9F?= Date: Sun, 13 Dec 2020 22:38:49 +0300 Subject: [PATCH 2/2] fix(schema): Add test cases for concatting and not overwriting (jquense/yup#1160) --- test/mixed.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/mixed.js b/test/mixed.js index c6551bf41..01ae82a8b 100644 --- a/test/mixed.js +++ b/test/mixed.js @@ -645,6 +645,19 @@ describe('Mixed Types ', () => { }.should.throw(TypeError)); }); + it('concat should not overwrite label and meta with undefined', function () { + const testLabel = "Test Label" + const testMeta = { + testField: "test field" + } + let baseSchema = mixed().label(testLabel).meta(testMeta) + const otherSchema = mixed() + + baseSchema = baseSchema.concat(otherSchema) + expect(baseSchema.spec.label).to.equal(testLabel) + expect(baseSchema.spec.meta.testField).to.equal(testMeta.testField) + }) + it('concat should allow mixed and other type', function () { let inst = mixed().default('hi');