H
Hono6d ago
DJ

Is there any way to mock cookies using testing helpers?

we already have testing helper and cookies helpers in Hono, but I can't find a way to inject cookies. I'm using Lucia with Hono together, they recommend to transfer session by cookies. Is this possible in test environment? if no, I have a worst plan is to create a custom app and takeover routes. and replace cookie middleware with bearer token middleware. how do you think?
5 Replies
DJ
DJ6d ago
it("should return user info", async () => {
const res = await client.api.user.$get(undefined, {
headers: { Cookie },
});
const data = await res.json();
expect(data).not.toBeNull();
});
it("should return user info", async () => {
const res = await client.api.user.$get(undefined, {
headers: { Cookie },
});
const data = await res.json();
expect(data).not.toBeNull();
});
im doing this, it's worked, i don't know what's happend.
Aditya Mathur
Aditya Mathur6d ago
What is Cookie? and how are you adding cookies in your frontend?
DJ
DJ5d ago
Cookie is a string returned by the backend via response headers (Set-Cookie). In the production environment, the browser will automatically send cookies. Only in the test environment, I will manually add Cookie to the headers. For me this solve the problem.
Aditya Mathur
Aditya Mathur5d ago
Usually the behavior is that we get connect to a test env where their is mock user, which we use to get the cookie.
Kaelwd
Kaelwd5d ago
GitHub
hono-session/test/setup.ts at master · KaelWD/hono-session
Contribute to KaelWD/hono-session development by creating an account on GitHub.
Want results from more Discord servers?
Add your server