I have some mocha tests using supertest and I've run into a case where independent tests (separate test files) are not re-initing the agent and start out in another test with the same cookie jar from the last.
I'm assuming this is because of the run-once nature of require, and that I'm getting one singleton agent instance (I think I more or less verified this looking at the source.) Is there a way I can clear the cookiejar in the beforeEach call in mocha?
Thanks!
Is this possibly because I need to close the instance of the app inside supertest in my after mocha teardown?
Depends on how your tests are setup. If you put a gist help, I can offer some advice.
Reopen when you have more details.
:+1:
Did anyone ever find a solution for this? I've been using set('Cookie', []) on the required requests but am hoping there is a more elegant solution.
I find that the instance of supertest created byrequire('supertest').agent(server)will persist cookie between unit test. require('supertest')(server)will not.
Most helpful comment
I find that the instance of supertest created by
require('supertest').agent(server)will persist cookie between unit test.require('supertest')(server)will not.