Supertest: Clear cookies between requests

Created on 4 Nov 2013  路  6Comments  路  Source: visionmedia/supertest

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!

question

Most helpful comment

I find that the instance of supertest created byrequire('supertest').agent(server)will persist cookie between unit test. require('supertest')(server)will not.

All 6 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NBNARADHYA picture NBNARADHYA  路  4Comments

rkmax picture rkmax  路  5Comments

bookercodes picture bookercodes  路  5Comments

EverettQuebral picture EverettQuebral  路  3Comments

jon301 picture jon301  路  5Comments