-
Notifications
You must be signed in to change notification settings - Fork 758
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
Unintuitive Set-Cookie behavior #413
Comments
Hello, I just tried your example using supertest version 2 and 3 and both are working for what you expect. ie this is true: What version of express are you using?
|
Hey @mikelax I wasn't very clear above... but that's not the line that is giving me problems. These two lines are the issue: 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? Yes, they pass... because I put the passing code into the snippet. My concerns are in the comments. I expect the cookies to be in an array just like expect(200, ['one=1; Path=/', 'two=2; Path=/']) // This is what I expect below but it's not. |
hmm, weird I just tried two different scripts and in both cases I am seeing the cookie be an array of two values, ie. what you are expecting. Here are the scripts: Server const express = require('express');
const supertest = require('supertest');
const compression = require('compression');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
app.use(compression());
app.use(bodyParser.json());
app.get('/cookie', (req, res) => {
// res.cookie('name', 'tobi', { domain: '.example.com', path: '/admin', secure: true });
res.cookie('one', '1');
res.cookie('two', '2');
res.json(res._headers['set-cookie']);
}); Mocha Test 1 it.only('Get cookie header', done => {
supertest.agent(app)
.get('/cookie')
.expect(200)
.end((err, res) => {
console.log(res.headers['set-cookie']);
console.log(res.headers['set-cookie'].length);
console.log(res.body);
if (err) return done(err);
done();
});
}); Mocha Test 2 (using .agent) it.only('Get cookie header', done => {
supertest.agent(app)
.get('/cookie')
.expect(200)
.then(res => {
console.log(res.headers['set-cookie']);
console.log(res.headers['set-cookie'].length);
console.log(res.body);
done();
});
}); Output for both cases:
|
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 |
👍, looks like I'm hitting this exact issue too. Also running jest. For people coming here via google, here is a workaround: jestjs/jest#3547 (comment) |
No?
The text was updated successfully, but these errors were encountered: