index.test.ts
This file
Path
src/helper/testing/index.test.ts
42 lines · 1.6 KiB · TypeScript
Last changed by
chore: let oxfmt sort imports instead of eslint (#5442)Yusuke Wadabefore adoption859e2c2
History of this fileTake it
The walk stopped after 200 commits: lines older than f0b094d point at it.
Merge commit from forkYusuke Wadabefore adoptionf0b094d
line 1why, one step back1import { testClient } from '.'chore: let oxfmt sort imports instead of eslint (#5442)Yusuke Wadabefore adoption859e2c2
line 2why, one step back2import { Hono } from '../../hono'Merge commit from forkYusuke Wadabefore adoptionf0b094d
lines 3–42why, one step back34describe('hono testClient', () => {5 it('Should return the correct search result', async () => {6 const app = new Hono().get('/search', (c) => c.json({ hello: 'world' }))7 const res = await testClient(app).search.$get()8 expect(await res.json()).toEqual({ hello: 'world' })9 })1011 it('Should return the correct environment variables value', async () => {12 type Bindings = { hello: string }13 const app = new Hono<{ Bindings: Bindings }>().get('/search', (c) => {14 return c.json({ hello: c.env.hello })15 })16 const res = await testClient(app, { hello: 'world' }).search.$get()17 expect(await res.json()).toEqual({ hello: 'world' })18 })1920 it('Should use the passed in headers', async () => {21 const app = new Hono().get('/search', (c) => {22 return c.json({ query: c.req.header('x-query') })23 })24 const res = await testClient(app, undefined, undefined, {25 headers: { 'x-query': 'abc' },26 }).search.$get()27 expect(await res.json()).toEqual({ query: 'abc' })28 })2930 it('Should return a correct URL with out throwing an error', async () => {31 const app = new Hono().get('/abc', (c) => c.json(0))32 const url = testClient(app).abc.$url()33 expect(url.pathname).toBe('/abc')34 })3536 it('Should not throw an error with $ws()', async () => {37 vi.stubGlobal('WebSocket', class {})38 const app = new Hono().get('/ws', (c) => c.text('Fake response of a WebSocket'))39 // @ts-expect-error $ws is not typed correctly40 expect(() => testClient(app).ws.$ws()).not.toThrowError()41 })42})