Last Updated: January 03, 2022
·
40.44K
· dakuan

Settings cookies for SuperTest

SuperTest Is a great tool for integration testing Node apps. I ran into a bit of bother with some cookie based stuff. I found some great tutorials for handling cookies eg this one. Nothing for what I wanted to do, which was to rig cookies to fixed values that corresponded to some seed dummy data. Turned out to be easy enough though:

request(url)
     .post('/some/place')
     .set('Accept-Language', 'en')
     .set('Cookie', ['myApp-token=12345667', 'myApp-other=blah'])
     .end(function(err, result){
          // test the result
     });

and in express they will arrive in the req.cookies:

console.log(req.cookies); //{'myApp-token': 12345667, 'myApp-other': 'blah'}

1 Response
Add your response

This is incorrect now. Should be:
.set('Cookie', 'myApp-token=12345667;myApp-other=blah')

over 1 year ago ·