chai-return-bool
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Build Status Coverage Status npm version

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 = require('chai').expect;
// ...
expect(foo()).to.be.closeTo(10, 1e-10);

You want a boolean true or false instead of an exception. You can wrap the assertion with chai-return-bool.

const expect = require('chai').expect;
const returnBool = require('chai-return-bool').returnBool;
// ...
returnBool(() => expect(foo()).to.be.closeTo(10, 1e-10)); // 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.
 */
function returnBool<T>(block: () => T): T extends Promise<any> ? Promise<boolean> : boolean

Readme

Keywords

Package Sidebar

Install

npm i chai-return-bool

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

7.51 kB

Total Files

9

Last publish

Collaborators

  • justinlovinger