Nock tough-cookie, cookiejar #2284
-
Is it possible to use nock to unit test the same cookie jar is shared between requests? I'm in the process of replacing react-promise-native with axios and then using nock in our jest unit tests. The code now uses tough-cookie to create a cookie jar, one of the old unit tests was it('shares the same cookie jar between first and second requests'). Can I use nock to set a cookie for the first response that is returned, and check it gets passed in on the second request? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes you can. You need to make sure the response from the first request includes a https://github.com/nock/nock#specifying-reply-headers |
Beta Was this translation helpful? Give feedback.
Yes you can.
You need to make sure the response from the first request includes a
set-cookie
header, then the second request can assert the presence of acookie
header with the expected value.https://github.com/nock/nock#specifying-reply-headers
https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies