From 484197f0e44ca42112a5ae54615d5e0173769236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Mon, 13 Aug 2018 11:16:09 +0100 Subject: [PATCH] Add test for nested object in typings --- test/typings.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/typings.ts b/test/typings.ts index ccbf0c3..9b5d35b 100644 --- a/test/typings.ts +++ b/test/typings.ts @@ -205,6 +205,36 @@ if (noRequiredFieldsValidator(input)) { if (typeof input.c !== 'undefined') assertType(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(input.email) + if (typeof input.email !== 'undefined') assertType(input.email) + assertType(input.paymentInformation.plan) + assertType(input.paymentInformation.token) +} + const animalValidator = createValidator({ oneOf: [ {