29 lines
694 B
JavaScript
29 lines
694 B
JavaScript
/* eslint-disable no-undef */
|
|
const TypeObject = require('./object.js')
|
|
const TypeString = require('./string.js')
|
|
|
|
describe('test validate type schema object', () => {
|
|
function throwFunc (val) {
|
|
return () => {
|
|
if (val) throw new Error(val)
|
|
}
|
|
}
|
|
|
|
it('test object type with required', async () => {
|
|
const obj = new TypeObject().required()
|
|
|
|
throwFunc(obj.validate({}))
|
|
|
|
expect(throwFunc(obj.validate(undefined))).toThrow()
|
|
expect(throwFunc(obj.validate(false))).toThrow()
|
|
})
|
|
|
|
it('test object type with child', async () => {
|
|
const obj = new TypeObject({
|
|
name: new TypeString()
|
|
}).required()
|
|
|
|
throwFunc(obj.validate({ name: 'asd' }))
|
|
})
|
|
})
|