Skip to content

Commit

Permalink
Schema.union: Better tests + Test for .optional()
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Apr 29, 2023
1 parent a79d75c commit 37c3687
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/schema/api/union.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,22 @@ test("matchSome union", (t) => {

test("Union inside dict", (t) => {
const schema = SchemaDict({
a: SchemaUnion({
v: SchemaStr<string>(),
z: SchemaNum<number>(),
field: SchemaUnion({
str: SchemaStr<string>(),
num: SchemaNum<number>(),
}),
});

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<string>(),
num: SchemaNum<number>(),
}).optional(),
});

t.true(schema.parse({ inner: 3 }).unwrap().inner.unwrap().is("num"));
});

0 comments on commit 37c3687

Please sign in to comment.