Skip to content

Test Promise without trying expect() inside then() callback. #1502

Discussion options

You must be logged in to vote

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
})

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@keithamus
Comment options

@AlirezaEthDev
Comment options

@keithamus
Comment options

@AlirezaEthDev
Comment options

@AlirezaEthDev
Comment options

Answer selected by keithamus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1501 on February 14, 2023 14:11.