The ambiguity of testClient()
documentation
#2497
PlayerNguyen
started this conversation in
General
Replies: 2 comments 1 reply
-
Additional information
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Same was happening to me until I made some tests on how I create my Hono instance. This works: // app.spec.ts
import { testClient } from 'hono/testing'
import { Hono } from 'hono'
const app = new Hono().get('/', (c) =>
c.json({
message: 'Hello, Hono!',
}),
)
describe('app', () => {
it('works', async () => {
const res = await testClient(app).index.$get()
expect(await res.json()).toEqual({
message: 'Hello, Hono!',
})
})
}) This does not: // app.spec.ts
import { testClient } from 'hono/testing'
import { Hono } from 'hono'
const app = new Hono()
app.get('/', (c) =>
c.json({
message: 'Hello, Hono!',
}),
)
describe('app', () => {
it('works', async () => {
const res = await testClient(app).index.$get() // Object is of type 'unknown'.ts(2571)
expect(await res.json()).toEqual({
message: 'Hello, Hono!',
})
})
}) So the problem is being caused by not chaining your routes directly after creating the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
After searching a documentation for the endpoint testing, I found that the test helper
testClient
documentation (which kinda depends onhc<...>()
) is very ambigous. Since this discussion is created totestClient<...>()
Reason
After looking at the source code, I found that the function
testClient<>(app)
is returning a unknown type. Although I already tried to put the generic tags onto it.Examples
Here is my current project
Beta Was this translation helpful? Give feedback.
All reactions