From e8e5b469e61a366288faec4ab664757fbb25fecd Mon Sep 17 00:00:00 2001 From: cemalettin-simsoft <69463668+cemalettin-simsoft@users.noreply.github.com> Date: Sun, 13 Dec 2020 22:43:10 +0300 Subject: [PATCH] fix: do not initialize spec values with undefined (#1177) * fix(schema): Don't initialize spec values with undefined (jquense/yup#1160) Concatting schemas can overwrite previous non-undefined values with undefined * fix(schema): Add test cases for concatting and not overwriting (jquense/yup#1160) --- src/schema.ts | 2 -- test/mixed.js | 13 +++++++++++++ 2 files changed, 13 insertions(+), 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, 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');