-
-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(testing): set `baseUrl` for `testClient` * denoify
- Loading branch information
Showing
3 changed files
with
18 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
import { Hono } from '../../hono' | ||
import { testClient } from '.' | ||
|
||
describe('hono testClinet', () => { | ||
it('should return the correct search result', async () => { | ||
describe('hono testClient', () => { | ||
it('Should return the correct search result', async () => { | ||
const app = new Hono().get('/search', (c) => c.json({ hello: 'world' })) | ||
const res = await testClient(app).search.$get() | ||
expect(await res.json()).toEqual({ hello: 'world' }) | ||
}) | ||
|
||
it('should return the correct environment variables value', async () => { | ||
it('Should return the correct environment variables value', async () => { | ||
type Bindings = { hello: string } | ||
const app = new Hono<{ Bindings: Bindings }>().get('/search', (c) => { | ||
return c.json({ hello: c.env.hello }) | ||
}) | ||
const res = await testClient(app, { hello: 'world' }).search.$get() | ||
expect(await res.json()).toEqual({ hello: 'world' }) | ||
}) | ||
|
||
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() | ||
expect(url.pathname).toBe('/abc') | ||
}) | ||
|
||
it('Should not throw an error with $ws()', async () => { | ||
vi.stubGlobal('WebSocket', class {}) | ||
const app = new Hono().get('/ws', (c) => c.text('Fake response of a WebSocket')) | ||
// @ts-expect-error $ws is not typed correctly | ||
expect(() => testClient(app).ws.$ws()).not.toThrowError() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters