avajs / ava

Node.js test runner that lets you develop with confidence 🚀
MIT License
20.74k stars 1.41k forks source link

`t.throws` doesn't recognize falsy thrown values #3312

Closed gibson042 closed 9 months ago

gibson042 commented 9 months ago

t.throws documents that an expectation with property "any" set to true should result in a passing assertion when the function throws a non-error value, which doesn't work when the thrown value is falsy.

Concretely, the following test should pass:

test("throws(throwsFalse)", t => {
  t.throws(() => { throw false; }, { any: true });
});

but instead fails against ava version 6.1.1:

   2: test("throws(throwsFalse)", t => {                      
   3:   t.throws(() => { throw false; }, { any: true });
   4: });                                               

  Function returned:

  undefined