diff --git a/src/helper/testing/index.test.ts b/src/helper/testing/index.test.ts index 3c474483b..d0a903e97 100644 --- a/src/helper/testing/index.test.ts +++ b/src/helper/testing/index.test.ts @@ -17,6 +17,16 @@ describe('hono testClient', () => { expect(await res.json()).toEqual({ hello: 'world' }) }) + it('Should use the passed in headers', async () => { + const app = new Hono().get('/search', (c) => { + return c.json({ query: c.req.header('x-query') }) + }) + const res = await testClient(app, undefined, undefined, { + headers: { 'x-query': 'abc' }, + }).search.$get() + expect(await res.json()).toEqual({ query: 'abc' }) + }) + it('Should return a correct URL with out throwing an error', async () => { const app = new Hono().get('/abc', (c) => c.json(0)) const url = testClient(app).abc.$url() diff --git a/src/helper/testing/index.ts b/src/helper/testing/index.ts index edf3b3e31..fc9606364 100644 --- a/src/helper/testing/index.ts +++ b/src/helper/testing/index.ts @@ -4,7 +4,7 @@ */ import { hc } from '../../client' -import type { Client } from '../../client/types' +import type { Client, ClientRequestOptions } from '../../client/types' import type { ExecutionContext } from '../../context' import type { Hono } from '../../hono' import type { Schema } from '../../types' @@ -16,11 +16,12 @@ type ExtractEnv = T extends Hono ? E : never export const testClient = >( app: T, Env?: ExtractEnv['Bindings'] | {}, - executionCtx?: ExecutionContext + executionCtx?: ExecutionContext, + options?: Omit ): UnionToIntersection> => { const customFetch = (input: RequestInfo | URL, init?: RequestInit) => { return app.request(input, init, Env, executionCtx) } - return hc('http://localhost', { fetch: customFetch }) + return hc('http://localhost', { ...options, fetch: customFetch }) }