jest-supertest-cookie-fix v1.0.0
jest-supertest-cookie-fix
Fixes an issue with supertest where cookies are not set properly when testing with jest.
In reference to issues supertest#413, supertest#460 and jest#3547. It seems that jest sets the cookies as a single string which then causes issues when the cookies try to get parsed. This library aims to provide a quick and simple solution to this issue.
Install
Install with yarn
:
$ yarn add jest-supertest-cookie-fix --dev
Or use npm
if you wish:
$ npm install jest-supertest-cookie-fix --save-dev
Usage
The easiest way to use this package is simply to import the fixed agent that is exported. Then use it normally the way you would use the supertest agent.
const agent = require('jest-supertest-cookie-fix');
agent(app).get('/').expect(200);
You can also import fixedSupertestAgent()
and pass it an instance of an agent.
const request = require('supertest');
const fixedSupertestAgent = require('jest-supertest-cookie-fix').fixedSupertestAgent;
const agent = request.agent(app);
const fixedAgent = fixedSupertestAgent(agent);
License
jest-supertest-cookie-fix is available under the MIT License.
Contributing
Contributions are welcome. Feel free to open an issue or submit a pull request.
7 years ago