[fix] add types init values

This commit is contained in:
Jay 2020-06-10 14:13:34 +00:00
parent a6d39d487a
commit 464e42ba1c
2 changed files with 22 additions and 5 deletions

View File

@ -4,11 +4,11 @@ const validator = {}
module.exports = validator
validator.Base = types.Base
validator.string = () => new types.StringType()
validator.number = () => new types.NumberType()
validator.boolean = () => new types.BooleanType()
validator.array = () => new types.ArrayType()
validator.object = () => new types.ObjectType()
validator.string = (...args) => new types.StringType(...args)
validator.number = (...args) => new types.NumberType(...args)
validator.boolean = (...args) => new types.BooleanType(...args)
validator.array = (...args) => new types.ArrayType(...args)
validator.object = (...args) => new types.ObjectType(...args)
/**
* validate

View File

@ -23,4 +23,21 @@ describe('test validator validate', () => {
expect(() => validator.validate(data, schema)).toThrow()
})
test('validate test 3', () => {
const data = {
str: '123',
strWithPattern: 'asd',
objWithChild: {
name: 'asd'
}
}
const schema = {
str: validator.string().required(),
strWithPattern: validator.string().pattern(/^asd$/).required(),
objWithChild: validator.object({ name: validator.string().required() }).required()
}
validator.validate(data, schema)
})
})