Skip to content
Myr

fix(client): send falsy JSON bodies (#5215)

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

authored by Ersa Oktavian Ramadan · committed by GitHub · parent a1e4ac7 · Browse files · 2 files+15 added−1 removed
This commit

State

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

Diff stats

2 files+15 added−1 removed

  • tests:+14 added−0 removed
  • other:+1 added−1 removed

2 files+15 added−1 removed

modified:src/client/client.test.ts+14 added
883 unmodified lines
884 const client = hc<AppType>('', { fetch: app.request })885 const res = await client.search.$get()886 expect(res.ok).toBe(true)887 })888889 it.each([false, 0, '', null])('Should send falsy JSON value: %j', async (json) => {890 const app = new Hono().post(891 '/json',892 validator('json', (value) => value as boolean | number | string | null),893 (c) => c.json(c.req.valid('json'))894 )895 const client = hc<typeof app>('', { fetch: app.request })896897 const res = await client.json.$post({ json })898899 expect(res.status).toBe(200)900 expect(await res.json()).toBe(json)901 })902})903904describe('Optional parameters in JSON response', () => {905 it('Should return the correct type', async () => {
1113 unmodified lines
modified:src/client/client.ts+1 added-1 removed
76 unmodified lines
77 }78 this.rBody = form79 }8081 if (args.json) {81 if (args.json !== undefined) {82 this.rBody = JSON.stringify(args.json)83 this.cType = 'application/json'84 }85
147 unmodified lines