Skip to content

Commit c6af9a8

Browse files
committed
add failing test case for #872
1 parent e715e00 commit c6af9a8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/validator/query.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,34 @@ describe('Query Validator', () => {
200200
expect(await res.json()).toEqual({ param1: true })
201201
})
202202

203+
it('parse optional boolean string with second parameter', async () => {
204+
const schema = t.Object({
205+
registered: t.Optional(t.Boolean()),
206+
other: t.String(),
207+
})
208+
const app = new Elysia().get('/', ({ query }) => query, {
209+
query: schema
210+
})
211+
const res = await app.handle(req('/?other=sucrose'))
212+
213+
expect(res.status).toBe(200)
214+
expect(await res.json()).toEqual({ other: 'sucrose' })
215+
})
216+
217+
it('parse optional boolean string with default value', async () => {
218+
const schema = t.Object({
219+
registered: t.Optional(t.Boolean({default: true})),
220+
other: t.String(),
221+
})
222+
const app = new Elysia().get('/', ({ query }) => query, {
223+
query: schema
224+
})
225+
const res = await app.handle(req('/?other=sucrose'))
226+
227+
expect(res.status).toBe(200)
228+
expect(await res.json()).toEqual({ other: 'sucrose', registered: true })
229+
})
230+
203231
it('validate optional object', async () => {
204232
const app = new Elysia().get(
205233
'/',

0 commit comments

Comments
 (0)