question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unintuitive Set-Cookie behavior

See original GitHub issue
const request = require('supertest');

const app = require('express')()
  .get('/cookies', (req, res, next) => {
    res.cookie('one', '1');
    res.cookie('two', '2');
    res.json(res._headers['set-cookie']);
  });

describe('/cookies', () => {
  it('should have correct anatomy', () =>
    request.agent(app)
      .get('/cookies')
      .expect(200, ['one=1; Path=/', 'two=2; Path=/']) // This is what I expect below
      .then(res => {
        expect(res.headers['set-cookie'].length).toBe(1); // should be 2
        expect(res.headers['set-cookie']).toEqual(['one=1; Path=/,two=2; Path=/']); // why is this a single string?
      })
  );
});

No?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jaygoodcommented, Jun 8, 2017

Oh that is odd. I just tried with mocha and am getting

[ 'one=1; Path=/', 'two=2; Path=/' ]

whereas jest is getting

[ 'one=1; Path=/,two=2; Path=/' ]

I’ll have to dig into what they’re doing…

Thanks

0reactions
jbintocommented, Jul 13, 2017

👍, looks like I’m hitting this exact issue too. Also running jest.

For people coming here via google, here is a workaround: https://github.com/facebook/jest/issues/3547#issuecomment-302550427

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unintuitive Set-Cookie behavior · Issue #413 · ladjs/supertest
agent(app) .get('/cookies') .expect(200, ['one=1; Path=/', 'two=2; Path=/']) // This is what I expect below .then(res => { expect(res.headers[' ...
Read more >
php - Why are my cookies not setting? - Stack Overflow
The problem comes from the fact that setcookie() doesn't set the cookies immediately, it sends the headers so the browser sets the cookies....
Read more >
Cookie storage behavior - HTTPie 3.2.1 (latest) docs
There are three possible sources of persisted cookies within a session. They have the following storage priority: 1—response; 2—command line; 3—session file ...
Read more >
PHP :: Bug #67736 :: setcookie() not updating existing cookies
The idea of having setcookie magically modifying the cookie header that is sent is not good. It would be adding more magic behaviour...
Read more >
Set-cookie ignored for HTTP response with status 302 - Monorail
Not on Ubuntu Version 24.0.1312.52 m though, strange issue. The issue is as is, Cookie's does not being set while sending 302 response...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found