describe('POST /users', (done) => {
it('should create a user', async () => {
const email = 'examplee@example.com'
const username = 'jpancakee'
const password = '123mnb!'
const res = await app
.post('/users/register')
.send({ username, email, password })
expect(res).to.have.status(200)
expect(res).to.have.header('x-auth')
expect(res.body._id).to.exist
expect(res.body.email).to.eql(email)
try {
const user = await User.findOne({ email })
expect(user).exist
expect(user.password).to.not.eql(password)
} catch (e) {
done(e)
}
})
})
I'm trying to do some async testing but done is not working correctly? im using mocha chai and chai-http. So the test passes as is but if I emulate an error in the try block lets say to .to.eql(password) it gives me the error
done is not a function.
What I expect is for the test to catch the error and throw it to done so it can display the error in the console.
any help will be appreciated :) thanks!
Aucun commentaire:
Enregistrer un commentaire