validator/types/object.test.js
Jay cdbecea36d
All checks were successful
continuous-integration/drone/push Build is passing
[chore] add test set
2020-06-10 14:15:02 +00:00

31 lines
756 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' }))
expect(throwFunc(obj.validate({ name: 123 }))).toThrow()
})
})