validator/types/object.test.js
Jay 46b19757bd
All checks were successful
continuous-integration/drone/push Build is passing
[feat] add string type pattern check, add object child check
2020-06-10 13:32:50 +00:00

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' }))
})
})