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
Response cookies could be parsed #481
Comments
See:
Shame on this module. I use https://github.com/nfriedly/set-cookie-parser for my tests. Even it would be nice to get it built-in, I think this isn't required, because you get it very cheap:
|
@Bessonov I like your approach! I agree the Even with your helpful approach, it would be very nice to have the ability to go through a json dictionary of cookie names and their corresponding flags via |
Has there been any move towards this? I use supertest a lot and it would be a great feature |
@LuisOsta havent seen anything on this so i wrote a small parser (~15 lines). feel free to drop it into your codebase. heres the gist, it includes jest tests as well output shape const cookies = {
cookieName: {
value: 'cookie value',
flags: {
flagName: 'flag value',
booleanFlag: true, // boolean flags (no value) are given true as their value
},
},
}; usage const app = require('./app');
const request = require('supertest');
const { extractCookies } = require('./utils/extract-cookies');
test('some test needing cookie details', async () => {
const res = await request(app).post('/tokens', { ...data });
const cookies = extractCookies(res.headers); // or res.header alias
// do tests on cookies, cookies.cookieName.[value, flags.[flagName]]
}); |
Getting cookies from the agent worked for me.
There's also |
Thank you for the great package. I use it all the time in my tests.
I'm testing response cookies and I realized in order to get response cookies I need to do something like this
And then dig through the set cookie header to verify that the correct cookie was returned. To make this easier, I converted the set-cookie header array to a dictionary using the cookie module
If this was part of supertest and could be used as an object off of the response object, it would be very helpful. I imagine a format something like this:
What do you think? Good idea? Would you accept a PR for this?
The text was updated successfully, but these errors were encountered: