Wondering what’s next for npm?Check out our public roadmap! »

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

    1.0.13 • Public • Published

    chai-quantifiers

    Array quantifier assertions for Chai assertion library.

    Build Status Coverage Status Maintainability node code style Types License Status

    Install

    npm install --save-dev chai chai-quantifiers

    Usage

    There are three assertions available, applicable to arrays.

    • containAll -- Asserts that all array items are true in respect to a predicate.
    • containOne -- Asserts that at least one array item is true in respect to a predicate.
    • containExactlyOne -- Asserts that exactly one array item is true in respect to a predicate.

    A quick example:

    const chai = require('chai');
    const chaiQuantifiers = require('chai-quantifiers');
    
    chai.use(chaiQuantifiers);
    
    const { expect } = chai;
    
    describe('chai-quantifiers', () => {
      it('containAll should be true if all items are true', () => {
        expect([0, 1, 2, 3]).to.containAll(item => item < 4);
      });
      it('containOne should be true if at least one item is true', () => {
        expect([0, 1, 2, 3]).to.containOne(item => item >= 2);
      });
      it('containExactlyOne should be true if exactly one item is true', () => {
        expect([0, 1, 2, 3]).to.containExactlyOne(item => item === 2);
      });
    });

    This module also includes types for TypeScript.

    Install

    npm i chai-quantifiers

    DownloadsWeekly Downloads

    1,491

    Version

    1.0.13

    License

    MIT

    Unpacked Size

    8.89 kB

    Total Files

    13

    Last publish

    Collaborators

    • avatar