Skip to content
Myr

fix(client): replace optional params to url correctly (#3304)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yusuke Wada · committed by GitHub · parent 95a6b39 · Browse files · 3 files+28 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+28 added−4 removed

  • tests:+25 added−1 removed
  • other:+3 added−3 removed

3 files+28 added−4 removed

modified:src/client/client.test.ts+14 added-1 removed
813 unmodified lines
814 })815})816817describe('$url() with a param option', () => {818 const app = new Hono().get('/posts/:id/comments', (c) => c.json({ ok: true }))818 const app = new Hono()819 .get('/posts/:id/comments', (c) => c.json({ ok: true }))820 .get('/something/:firstId/:secondId/:version?', (c) => c.json({ ok: true }))821 type AppType = typeof app822 const client = hc<AppType>('http://localhost')823824 it('Should return the correct path - /posts/123/comments', async () => {
8 unmodified lines
833 it('Should return the correct path - /posts/:id/comments', async () => {834 const url = client.posts[':id'].comments.$url()835 expect(url.pathname).toBe('/posts/:id/comments')836 })837838 it('Should return the correct path - /something/123/456', async () => {839 const url = client.something[':firstId'][':secondId'][':version?'].$url({840 param: {841 firstId: '123',842 secondId: '456',843 version: undefined,844 },845 })846 expect(url.pathname).toBe('/something/123/456')847 })848})849850describe('Client can be awaited', () => {851 it('Can be awaited without side effects', async () => {
453 unmodified lines
modified:src/client/utils.test.ts+11 added
modified:src/client/utils.ts+3 added-3 removed