Skip to content

Commit

Permalink
fix: do not initialize spec values with undefined (#1177)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
cemalettin-work committed Dec 13, 2020
1 parent e785e1a commit e8e5b46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions test/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit e8e5b46

Please sign in to comment.