Skip to content

Commit ca52f96

Browse files
committed
feat: add support for complex nested object schemas in tests
1 parent f35bf57 commit ca52f96

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

packages/spur/src/__tests__/leitplanken/object.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,39 @@ describe('object schema', () => {
160160
await expect(parse(schema, { name: 'Spur' })).resolves.toEqual({ name: 'Spur' })
161161
await expect(parse(schema, { name: 'Spur', nickname: 'S' })).resolves.toEqual({ name: 'Spur', nickname: 'S' })
162162
})
163+
164+
it('allows for a complex nested object schema', async () => {
165+
const schema = object({
166+
id: string().minLength(5),
167+
profile: object({
168+
name: string().minLength(2),
169+
age: number().min(0).optional(),
170+
contact: object({
171+
email: string().exactOptional(),
172+
phone: string().undefinable(),
173+
}).optional(),
174+
}),
175+
tags: object({
176+
primary: string(),
177+
secondary: string().optional(),
178+
}).optional(),
179+
})
180+
181+
expect(async () => await parse(schema, {
182+
id: 'user_12345',
183+
profile: {
184+
name: 'Alice',
185+
age: 28,
186+
contact: {
187+
email: 'alice@example.com',
188+
phone: undefined,
189+
},
190+
},
191+
tags: {
192+
primary: 'admin',
193+
},
194+
})).not.toThrow()
195+
})
196+
197+
// TODO: test transform and the undefined, exactOptional extra logic
163198
})

0 commit comments

Comments
 (0)