2020-06-03 15:49:04 +00:00
|
|
|
/* eslint-disable no-undef */
|
|
|
|
const TypeObject = require('./object.js')
|
2020-06-10 13:32:50 +00:00
|
|
|
const TypeString = require('./string.js')
|
2020-06-03 15:49:04 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2020-06-10 13:32:50 +00:00
|
|
|
throwFunc(obj.validate({}))
|
2020-06-03 15:49:04 +00:00
|
|
|
|
|
|
|
expect(throwFunc(obj.validate(undefined))).toThrow()
|
|
|
|
expect(throwFunc(obj.validate(false))).toThrow()
|
|
|
|
})
|
2020-06-10 13:32:50 +00:00
|
|
|
|
|
|
|
it('test object type with child', async () => {
|
|
|
|
const obj = new TypeObject({
|
|
|
|
name: new TypeString()
|
|
|
|
}).required()
|
|
|
|
|
|
|
|
throwFunc(obj.validate({ name: 'asd' }))
|
2020-06-10 14:15:02 +00:00
|
|
|
|
|
|
|
expect(throwFunc(obj.validate({ name: 123 }))).toThrow()
|
2020-06-10 13:32:50 +00:00
|
|
|
})
|
2020-06-03 15:49:04 +00:00
|
|
|
})
|