You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.1 KiB

'use strict'
const test = require('tap').test
const build = require('..')
test('object with required field', (t) => {
t.plan(3)
const schema = {
title: 'object with required field',
type: 'object',
properties: {
str: {
type: 'string'
},
num: {
type: 'integer'
}
},
required: ['str']
}
const stringify = build(schema)
try {
stringify({
str: 'string'
})
t.pass()
} catch (e) {
t.fail()
}
try {
stringify({
num: 42
})
t.fail()
} catch (e) {
t.is(e.message, 'str is required!')
t.pass()
}
})
test('required numbers', (t) => {
t.plan(3)
const schema = {
title: 'object with required field',
type: 'object',
properties: {
str: {
type: 'string'
},
num: {
type: 'integer'
}
},
required: ['num']
}
const stringify = build(schema)
try {
stringify({
num: 42
})
t.pass()
} catch (e) {
t.fail()
}
try {
stringify({
num: 'aaa'
})
t.fail()
} catch (e) {
t.is(e.message, 'num is required!')
t.pass()
}
})