Compare commits

...

3 Commits

Author SHA1 Message Date
Jay
81bde1577c Merge pull request 'feature/modify-types-init-value' (#7) from feature/modify-types-init-value into develop
All checks were successful
continuous-integration/drone/push Build is passing
2020-06-10 14:17:29 +00:00
Jay
cdbecea36d [chore] add test set
All checks were successful
continuous-integration/drone/push Build is passing
2020-06-10 14:15:02 +00:00
Jay
464e42ba1c [fix] add types init values 2020-06-10 14:13:34 +00:00
3 changed files with 24 additions and 5 deletions

View File

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

View File

@ -24,5 +24,7 @@ describe('test validate type schema object', () => {
}).required() }).required()
throwFunc(obj.validate({ name: 'asd' })) throwFunc(obj.validate({ name: 'asd' }))
expect(throwFunc(obj.validate({ name: 123 }))).toThrow()
}) })
}) })

View File

@ -23,4 +23,21 @@ describe('test validator validate', () => {
expect(() => validator.validate(data, schema)).toThrow() 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)
})
}) })