From 37c3687879910bacd2b3ee07f8cf43134b93b23a Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 29 Apr 2023 23:54:24 +0300 Subject: [PATCH] Schema.union: Better tests + Test for .optional() --- src/schema/api/union.test.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/schema/api/union.test.ts b/src/schema/api/union.test.ts index 733c9b5..b6ec15f 100644 --- a/src/schema/api/union.test.ts +++ b/src/schema/api/union.test.ts @@ -114,11 +114,22 @@ test("matchSome union", (t) => { test("Union inside dict", (t) => { const schema = SchemaDict({ - a: SchemaUnion({ - v: SchemaStr(), - z: SchemaNum(), + field: SchemaUnion({ + str: SchemaStr(), + num: SchemaNum(), }), }); - t.true(schema.parse({ a: "" }).unwrap().a.is("v")); + t.true(schema.parse({ field: "" }).unwrap().field.is("str")); +}); + +test("Optional union", (t) => { + const schema = SchemaDict({ + inner: SchemaUnion({ + str: SchemaStr(), + num: SchemaNum(), + }).optional(), + }); + + t.true(schema.parse({ inner: 3 }).unwrap().inner.unwrap().is("num")); });