[fix] add types init values
This commit is contained in:
parent
a6d39d487a
commit
464e42ba1c
10
index.js
10
index.js
@ -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
|
||||
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user