hono
hono copied to clipboard
testClient in Deno cannot run normally unless add --no-check parameter
What version of Hono are you using?
3.11.12
What runtime/platform is your app running on?
deno
What steps can reproduce the bug?
import {Hono} from "hono";
import {test as it} from "node:test";
import {testClient} from "hono/testing";
// import {expect} from "chai";
it("hono testClinet", () => {
it("should return the correct search result", async () => {
let app = new Hono();
app.get("/search", (c) => c.json({hello: "world"}));
const res = await testClient(app)["search"].$get();
// expect(await res.json()).equal({hello: "world"});
});
});
❯ deno test test/hono_test.ts
Check file:///Users/chen/gemini-openai-proxy/test/hono_test.tso_test.ts
error: TS2571 [ERROR]: Object is of type 'unknown'.
const res = await testClient(app)["search"].$get();
~~~~~~~~~~~~~~~
at file:///Users/chen/gemini-openai-proxy/test/hono_test.ts:10:27
❯ deno test --no-check test/hono_test.ts
running 1 test from ./test/hono_test.ts
hono testClinet ... ok (0ms)
ok | 1 passed | 0 failed (3ms)
What is the expected behavior?
No need to add --no-check, the tests can run normally.
What do you see instead?
No response
Additional information
For those who encounter the same problem, you can now add the "--no-check" parameter to make the test run normally.
deno test --no-check
Hi. If you write it as the code below, it will work.
it("should return the correct search result", async () => {
let app = new Hono().get("/search", (c) => c.json({hello: "world"}));
const res = await testClient(app)["search"].$get();
// expect(await res.json()).equal({hello: "world"});
});
This is not a bug! You should write the code as mentioned above.
const app = new Hono().get('/search', (c) => c.json({ hello: 'world' }))
Closing.