Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How would you test cookies? #7

Open
EnriqueCepeda opened this issue Feb 10, 2024 · 1 comment
Open

How would you test cookies? #7

EnriqueCepeda opened this issue Feb 10, 2024 · 1 comment

Comments

@EnriqueCepeda
Copy link

Hi! In my company, we're using Remix, and we're making more or less the same approach of auth with Cookies, but haven't been able to test it correctly. We're trying to test that a loader has a cookie that an action has previously set with: redirect("/", {headers: {"Set-Cookie": "cookie=foo"}}). The problem is that the loader doesn't receive any cookie, and it has been impossible to test it using remixStub.

Testing auth is very important for us, but ideally, we don't want to start using an e2e tool such as playwright because Vitest (+ happy-dom) is way faster, is there anything you think we might be missing or do you have any comment?

Furthermore, it would be awesome if you show us how would you to test these kinds of examples!

@Sarvesh-Ghildiyal
Copy link

Hello @EnriqueCepeda, as per my understanding of the question, I think using our request object does give us access to the created cookie.
you can do so like this.

export async function loader(request:LoaderFunctionArgs) {

 const cook= await request.request.headers.get("cookie")
  console.log(cook)
  return null;

}

Although this approach would not be greatly suggested, rather have a server side module or function where you can call in the cookie and check up on things in any way you would like to, and you might call that function in any of the loader you would prefer to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants