Skip to content

Commit

Permalink
test: add test for issue #342
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-tymoshenko committed Jul 31, 2022
1 parent 7af554a commit 01608f2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/nullable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,37 @@ test('nullable type in the schema', (t) => {
t.same(stringify(data), JSON.stringify(data))
t.same(stringify(null), JSON.stringify(null))
})

test('throw an error if the value doesn\'t match the type', (t) => {
t.plan(2)

const schema = {
type: 'object',
additionalProperties: false,
required: ['data'],
properties: {
data: {
type: 'array',
minItems: 1,
items: {
oneOf: [
{
type: 'string'
},
{
type: 'number'
}
]
}
}
}
}

const stringify = build(schema)

const validData = { data: [1, 'testing'] }
t.equal(stringify(validData), JSON.stringify(validData))

const invalidData = { data: [false, 'testing'] }
t.throws(() => stringify(invalidData))
})

0 comments on commit 01608f2

Please sign in to comment.