chai-return-bool
A simple utility library to return a boolean with chai.js instead of raising an exception.
Installation
via npm
npm install chai-return-bool
Usage
Say you are using chai
to assert against a piece of code
const expect = expect;// ...tobe;
You want a boolean true
or false
instead of an exception. You can wrap the assertion with chai-return-bool
.
const expect = expect;const returnBool = returnBool;// ...; // Returns: true or false
chai-return-bool
works with all chai
assertion styles.
Async
If block
returns a Promise
, returnBool
returns a Promise
that resolves to true
or false
.
API
/** * Call block and return true if it does not raise a chai.AssertionError * * Return false if block returns a chai.AssertionError * * If any other exception is raised, that exception will not be caught by returnBool. */