Skip to content

Commit e8e5b46

Browse files
fix: do not initialize spec values with undefined (#1177)
* fix(schema): Don't initialize spec values with undefined (#1160) Concatting schemas can overwrite previous non-undefined values with undefined * fix(schema): Add test cases for concatting and not overwriting (#1160)
1 parent e785e1a commit e8e5b46

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/schema.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ export default abstract class BaseSchema<
137137
strict: false,
138138
abortEarly: true,
139139
recursive: true,
140-
label: undefined,
141-
meta: undefined,
142140
nullable: false,
143141
presence: 'optional',
144142
...options?.spec,

test/mixed.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,19 @@ describe('Mixed Types ', () => {
645645
}.should.throw(TypeError));
646646
});
647647

648+
it('concat should not overwrite label and meta with undefined', function () {
649+
const testLabel = "Test Label"
650+
const testMeta = {
651+
testField: "test field"
652+
}
653+
let baseSchema = mixed().label(testLabel).meta(testMeta)
654+
const otherSchema = mixed()
655+
656+
baseSchema = baseSchema.concat(otherSchema)
657+
expect(baseSchema.spec.label).to.equal(testLabel)
658+
expect(baseSchema.spec.meta.testField).to.equal(testMeta.testField)
659+
})
660+
648661
it('concat should allow mixed and other type', function () {
649662
let inst = mixed().default('hi');
650663

0 commit comments

Comments
 (0)