0
0
mirror of https://github.com/honojs/hono.git synced 2024-12-01 11:51:01 +01:00

fix(client): continue if query value is undefined (#1368)

* fix(client): `continue` if query value is `undefined`

* denoify
This commit is contained in:
Yusuke Wada 2023-08-23 09:11:25 +09:00 committed by GitHub
parent 2685a9b017
commit a168ed584b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View File

@ -42,7 +42,7 @@ class ClientRequestImpl {
if (args.query) {
for (const [k, v] of Object.entries(args.query)) {
if (v === undefined) {
return
continue
}
this.queryParams ||= new URLSearchParams()

View File

@ -128,15 +128,13 @@ describe('Basic - query, queries, form, and path params', () => {
.get(
'/search',
validator('query', () => {
return {} as { q: string; tag: string[] }
return {} as { q: string; tag: string[]; filter: string }
}),
(c) => {
return c.jsonT({
entries: [
{
title: 'Foo',
},
],
q: 'fake',
tag: ['fake'],
filter: 'fake',
})
}
)
@ -170,11 +168,13 @@ describe('Basic - query, queries, form, and path params', () => {
const url = new URL(req.url)
const query = url.searchParams.get('q')
const tag = url.searchParams.getAll('tag')
const filter = url.searchParams.get('filter')
return res(
ctx.status(200),
ctx.json({
q: query,
tag: tag,
tag,
filter,
})
)
}),
@ -209,6 +209,8 @@ describe('Basic - query, queries, form, and path params', () => {
query: {
q: 'foobar',
tag: ['a', 'b'],
// @ts-expect-error
filter: undefined,
},
})
@ -216,6 +218,7 @@ describe('Basic - query, queries, form, and path params', () => {
expect(await res.json()).toEqual({
q: 'foobar',
tag: ['a', 'b'],
filter: null,
})
})

View File

@ -42,7 +42,7 @@ class ClientRequestImpl {
if (args.query) {
for (const [k, v] of Object.entries(args.query)) {
if (v === undefined) {
return
continue
}
this.queryParams ||= new URLSearchParams()