Test Promise without trying expect() inside then() callback. #1502
Answered
by
keithamus
AlirezaEthDev
asked this question in
Support
-
As I read Chai Http, Whenever we need to test a promise by Chai Http, we should try
My questiona are:
|
Beta Was this translation helpful? Give feedback.
Answered by
keithamus
Feb 14, 2023
Replies: 1 comment 6 replies
-
Hey @AlirezaEthDev thanks for the issue. The best way to do this is with async/await: test('the thing', async () => {
expect(
await chai.request(app)
// ^ note the "await"
.send({ password: '123', confirmPassword: '123' })
).to.have.status(200)
}) If you can't use async await you could try chai-as-promised: chai.use(require('chai-as-promised'))
test('the thing', () => {
return expect(
chai.request(app)
.send({ password: '123', confirmPassword: '123' })
).to.eventually.have.status(200)
// ^ note the "eventually" from chai-as-promised
}) |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
keithamus
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @AlirezaEthDev thanks for the issue.
The best way to do this is with async/await:
If you can't use async await you could try chai-as-promised: