Skip to content

Commit a317c66

Browse files
test: add test for issue #342 (#497)
1 parent 7af554a commit a317c66

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/nullable.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,37 @@ test('nullable type in the schema', (t) => {
464464
t.same(stringify(data), JSON.stringify(data))
465465
t.same(stringify(null), JSON.stringify(null))
466466
})
467+
468+
test('throw an error if the value doesn\'t match the type', (t) => {
469+
t.plan(2)
470+
471+
const schema = {
472+
type: 'object',
473+
additionalProperties: false,
474+
required: ['data'],
475+
properties: {
476+
data: {
477+
type: 'array',
478+
minItems: 1,
479+
items: {
480+
oneOf: [
481+
{
482+
type: 'string'
483+
},
484+
{
485+
type: 'number'
486+
}
487+
]
488+
}
489+
}
490+
}
491+
}
492+
493+
const stringify = build(schema)
494+
495+
const validData = { data: [1, 'testing'] }
496+
t.equal(stringify(validData), JSON.stringify(validData))
497+
498+
const invalidData = { data: [false, 'testing'] }
499+
t.throws(() => stringify(invalidData))
500+
})

0 commit comments

Comments
 (0)