Skip to content

Commit

Permalink
Add test for nested object in typings
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU committed Aug 13, 2018
1 parent 4bec868 commit 484197f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,36 @@ if (noRequiredFieldsValidator(input)) {
if (typeof input.c !== 'undefined') assertType<string>(input.c)
}

const signupValidator = createValidator({
type: 'object',
properties: {
email: {
type: 'string'
},
paymentInformation: {
type: 'object',
properties: {
plan: { type: 'string' },
token: { type: 'string' }
},
required: [
'plan' as 'plan',
'token' as 'token'
]
}
},
required: [
'paymentInformation'
]
})

if (signupValidator(input)) {
if (typeof input.email !== 'string') assertType<undefined>(input.email)
if (typeof input.email !== 'undefined') assertType<string>(input.email)
assertType<string>(input.paymentInformation.plan)
assertType<string>(input.paymentInformation.token)
}

const animalValidator = createValidator({
oneOf: [
{
Expand Down

0 comments on commit 484197f

Please sign in to comment.