チャイクォンティファイア

チャイアサーションライブラリ向けの配列クォンティファイアアサーション。

main workflow Coverage Status Maintainability node code style Types License Status

インストール

npm install --save-dev chai chai-quantifiers

使用法

使用可能なアサーションは3つあり、配列に適用できます。

  • containAll – すべての配列アイテムが述語に関して true であることをアサートします。
  • containOne – 少なくとも1つの配列アイテムが述語に関して true であることをアサートします。
  • containExactlyOne – 正確に1つの配列アイテムが述語に関して true であることをアサートします。

簡単な例

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);
  });
});

このモジュールにはTypeScript用の型も含まれています。