6

I am just doing some API tests and I am trying to verify that the cookie data sent down is correct, however I cannot find any documentation around getting cookies from the response object, only from the request.

So is there a quick way to do this like you would do with the requests req.cookies["myCookie"], I know I can get the header and get the set-cookie one from there but its a bit of a mess trying to parse out the cookie data from there manually.

mscdex
  • 104,356
  • 15
  • 192
  • 153
Grofit
  • 17,693
  • 24
  • 96
  • 176
  • I think the first question is why not just use the request object? – mscdex Oct 03 '14 at 12:20
  • As supertest `expect` method provides me the response from the API. – Grofit Oct 03 '14 at 12:27
  • Ok, so why not just compare the raw expected `set-cookie` value, such as `.expect('set-cookie', 'cookie=hey; Path=/');`? – mscdex Oct 03 '14 at 12:36
  • 1
    because the cookie output changes each time, as it randomly generates an authentication token and some other stuff and is encrypted. So it *seemed easier* to just get the cookie and get the value, decrypt it and confirm that everything has been generate as per whats in the DB. So rather than having to do string matches on semi complex serialized data I just wanted to use `res.cookies` and was hoping someone out just tell me there is a simple way to get cookie data... apparently there is not... – Grofit Oct 03 '14 at 14:16

1 Answers1

5

Could not find a solution, had to end up doing a text match on the set-cookie header.

Grofit
  • 17,693
  • 24
  • 96
  • 176