File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,34 @@ describe('Query Validator', () => {
200
200
expect ( await res . json ( ) ) . toEqual ( { param1 : true } )
201
201
} )
202
202
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
+
203
231
it ( 'validate optional object' , async ( ) => {
204
232
const app = new Elysia ( ) . get (
205
233
'/' ,
You can’t perform that action at this time.
0 commit comments