Skip to content

Commit d14112b

Browse files
test: add test for issue #246 (#500)
1 parent b3f3baf commit d14112b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/nullable.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,46 @@ test('throw an error if the value doesn\'t match the type', (t) => {
498498
const invalidData = { data: [false, 'testing'] }
499499
t.throws(() => stringify(invalidData))
500500
})
501+
502+
test('nullable value in oneOf', (t) => {
503+
t.plan(1)
504+
505+
const schema = {
506+
type: 'object',
507+
properties: {
508+
data: {
509+
oneOf: [
510+
{
511+
type: 'array',
512+
items: {
513+
type: 'object',
514+
properties: {
515+
id: { type: 'integer', minimum: 1 }
516+
},
517+
additionalProperties: false,
518+
required: ['id']
519+
}
520+
},
521+
{
522+
type: 'array',
523+
items: {
524+
type: 'object',
525+
properties: {
526+
job: { type: 'string', nullable: true }
527+
},
528+
additionalProperties: false,
529+
required: ['job']
530+
}
531+
}
532+
]
533+
}
534+
},
535+
required: ['data'],
536+
additionalProperties: false
537+
}
538+
539+
const stringify = build(schema)
540+
541+
const data = { data: [{ job: null }] }
542+
t.equal(stringify(data), JSON.stringify(data))
543+
})

0 commit comments

Comments
 (0)