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:
parent
2685a9b017
commit
a168ed584b
@ -42,7 +42,7 @@ class ClientRequestImpl {
|
|||||||
if (args.query) {
|
if (args.query) {
|
||||||
for (const [k, v] of Object.entries(args.query)) {
|
for (const [k, v] of Object.entries(args.query)) {
|
||||||
if (v === undefined) {
|
if (v === undefined) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
this.queryParams ||= new URLSearchParams()
|
this.queryParams ||= new URLSearchParams()
|
||||||
|
@ -128,15 +128,13 @@ describe('Basic - query, queries, form, and path params', () => {
|
|||||||
.get(
|
.get(
|
||||||
'/search',
|
'/search',
|
||||||
validator('query', () => {
|
validator('query', () => {
|
||||||
return {} as { q: string; tag: string[] }
|
return {} as { q: string; tag: string[]; filter: string }
|
||||||
}),
|
}),
|
||||||
(c) => {
|
(c) => {
|
||||||
return c.jsonT({
|
return c.jsonT({
|
||||||
entries: [
|
q: 'fake',
|
||||||
{
|
tag: ['fake'],
|
||||||
title: 'Foo',
|
filter: 'fake',
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -170,11 +168,13 @@ describe('Basic - query, queries, form, and path params', () => {
|
|||||||
const url = new URL(req.url)
|
const url = new URL(req.url)
|
||||||
const query = url.searchParams.get('q')
|
const query = url.searchParams.get('q')
|
||||||
const tag = url.searchParams.getAll('tag')
|
const tag = url.searchParams.getAll('tag')
|
||||||
|
const filter = url.searchParams.get('filter')
|
||||||
return res(
|
return res(
|
||||||
ctx.status(200),
|
ctx.status(200),
|
||||||
ctx.json({
|
ctx.json({
|
||||||
q: query,
|
q: query,
|
||||||
tag: tag,
|
tag,
|
||||||
|
filter,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
@ -209,6 +209,8 @@ describe('Basic - query, queries, form, and path params', () => {
|
|||||||
query: {
|
query: {
|
||||||
q: 'foobar',
|
q: 'foobar',
|
||||||
tag: ['a', 'b'],
|
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({
|
expect(await res.json()).toEqual({
|
||||||
q: 'foobar',
|
q: 'foobar',
|
||||||
tag: ['a', 'b'],
|
tag: ['a', 'b'],
|
||||||
|
filter: null,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class ClientRequestImpl {
|
|||||||
if (args.query) {
|
if (args.query) {
|
||||||
for (const [k, v] of Object.entries(args.query)) {
|
for (const [k, v] of Object.entries(args.query)) {
|
||||||
if (v === undefined) {
|
if (v === undefined) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
this.queryParams ||= new URLSearchParams()
|
this.queryParams ||= new URLSearchParams()
|
||||||
|
Loading…
Reference in New Issue
Block a user