SteeveDroz SteeveDroz - 3 months ago 10
Node.js Question

Jasmine `expect` never wrong in superagent `end`

My code doesn't do what it should. All the Jasmine

expect()
that are in a supertest
end()
callback function pass, even if they should not.

const app = require('../server')
const request = require('supertest')

describe('Client', function() {
const agent = request.agent(app)

it('connects to the server', function() {
agent.post('/users/register/foobar').end(function(err, res) {
done()
expect(true).toBe(false) // Doesn't fail
}
})
})


Extract from
package.json
:

"devDependencies": {
"jasmine": "^2.4.1",
"supertest": "^2.0.0"
}


The actual versions given by
npm list
are
jasmine@2.4.1
and
supertest@2.0.0
.

My guess is that
end()
never calls its function, but I just started yesterday with all that and I'm not sure what to do to solve the problem.

Do you see my error?




Edit



As suggested, I switched lines to put the
done()
at the end, still no change, though.

Answer

I think you're wrong to use the function "done". Try:

it('connects to the server', function(done) {
agent.post('/users/register/foobar').end(function(err, res) {
  expect(true).toBe(false); // Doesn't fail
  done();
}  })

For more details, check the jasmine documentation: Jasmine documentation: Asynchronous Support

Comments