chaijs / chai

BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
https://chaijs.github.io
MIT License
8.15k stars 698 forks source link

How to assert async error? #1647

Closed danny0838 closed 1 month ago

danny0838 commented 1 month ago
assert.throw(async () => {
  // expect this to throw
  await somefunc(/* args */);
});

Something like the above code doesn't work as expected.

Is there a way to assert whether a promise should throw?

43081j commented 1 month ago

Currently I think you would need to use something like chai-as-promised. We really need to pull that capability into core I think, given how fundamental it is these days