Skip to content

How to set cookie header? #36

Answered by Xunnamius
janhesters asked this question in Q&A
Discussion options

You must be logged in to vote

The following test is currently passing. What behavior are you experiencing/expecting (see the issue template for an example)?

it('respects setting cookie using request patcher', async () => {
      expect.hasAssertions();

      const token = 'my-token';

      await testApiHandler({
        requestPatcher: (req) => (req.headers = { cookie: `magic-auth-token=${token}` }),

        handler: async (req: NextApiRequest, res: NextApiResponse) => {
          res.status(200).send({ data: req.headers.cookie });
        },

        test: async ({ fetch }) => {
          expect((await fetch()).status).toBe(200);
          expect(await (await fetch()).json()).toStrictEqual({
            data: `mag…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by Xunnamius
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@janhesters
Comment options

@Xunnamius
Comment options

@janhesters
Comment options

@janhesters
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #35 on January 22, 2021 19:38.