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'}
Written by Dominic Barker
Related protips
1 Response
This is incorrect now. Should be:
.set('Cookie', 'myApp-token=12345667;myApp-other=blah')
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#