From a168ed584b92b1dcb4a1e0db904064b29ba2b084 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Wed, 23 Aug 2023 09:11:25 +0900 Subject: [PATCH] fix(client): `continue` if query value is `undefined` (#1368) * fix(client): `continue` if query value is `undefined` * denoify --- deno_dist/client/client.ts | 2 +- src/client/client.test.ts | 17 ++++++++++------- src/client/client.ts | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/deno_dist/client/client.ts b/deno_dist/client/client.ts index 4b99f0dd..4c4dc171 100644 --- a/deno_dist/client/client.ts +++ b/deno_dist/client/client.ts @@ -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() diff --git a/src/client/client.test.ts b/src/client/client.test.ts index 7b3ad5fd..0d13686a 100644 --- a/src/client/client.test.ts +++ b/src/client/client.test.ts @@ -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, }) }) diff --git a/src/client/client.ts b/src/client/client.ts index 76a9d72c..997e333b 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -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()