Jest has detected the following 1 open handle potentially keeping Jest from exiting: TCPSERVERWRAP

I still haven’t found a perfect solution, but for the moment I went for this workaround : jest –config ./test/jest-e2e.json –forceExit The –forceExit option kill the openHandles somehow and unlock everything. Yet, I’m still looking for the “proper way” of handling that issue.

Trying to use supertest to check the body of response – getting an error

Alternatively, this should work too: res.body.should.have.property(“name”, “new_org”); Also, just a note but logically I think it makes sense to put this in another call to expects instead of in the final callback. This function can also be re-used, so I tend to put it somewhere reusable when possible: var isValidOrg = function(res) { res.body.should.have.property(“name”, “new_org”); … Read more

Testing requests that redirect with mocha/supertest in node

There is built-in assertion for this in supertest: should = require(‘should’) request = require(‘supertest’) app = require(‘../../app’) describe ‘authentication’, -> describe ‘POST /sessions’, -> describe ‘success’, -> it ‘redirects to the right path’, (done) -> request(app) .post(‘/sessions’) .send(user: ‘username’, password: ‘password’) .expect(302) .expect(‘Location’, ‘/home’) .end(done)

How to chain http calls with superagent/supertest?

Tried to put this in a comment above, formatting wasn’t working out. I’m using async, which is really standard and works really well. it(‘should respond to only certain methods’, function(done) { async.series([ function(cb) { request(app).get(“https://stackoverflow.com/”).expect(404, cb); }, function(cb) { request(app).get(‘/new’).expect(200, cb); }, function(cb) { request(app).post(“https://stackoverflow.com/”).send({prop1: ‘new’}).expect(404, cb); }, function(cb) { request(app).get(‘/0’).expect(200, cb); }, function(cb) { … Read more

How to send query string parameters using supertest?

Although supertest is not that well documented, you can have a look into the tests/supertest.js. There you have a test suite only for the query strings. Something like: request(app) .get(“https://stackoverflow.com/”) .query({ val: ‘Test1’ }) .expect(200, function(err, res) { res.text.should.be.equal(‘Test1’); done(); }); Therefore: .query({ key1: value1, … keyN: valueN }) should work.

How to authenticate Supertest requests with Passport?

As zeMirco points out, the underlying superagent module supports sessions, automatically maintaining cookies for you. However, it is possible to use the superagent.agent() functionality from supertest, through an undocumented feature. Simply use require(‘supertest’).agent(‘url’) instead of require(‘supertest’)(‘url’): var request = require(‘supertest’); var server = request.agent(‘http://localhost:3000’); describe(‘GET /api/getDir’, function(){ it(‘login’, loginUser()); it(‘uri that requires user to be … Read more