vendredi 10 janvier 2020

Javascript chai why throw not caught?

I'm testing a Nodejs server using mocha and chai on Windows 10. One function to access a database throws if the key is not existent. Why putting it under expect like this:

expect(db.getReferenceData("not-existent")).to.throw();

fails? Instead, putting it inside another function works:

expect(function() {
    db.getReferenceData("not-existent");
}).to.throw();

The examples in the documentation seem to imply the first call is correct, at least for me.

Thanks for your help! mario

Aucun commentaire:

Enregistrer un commentaire