https://github.com/funny-bytes/chai-quantifiers
Array quantifier assertions for chai.
https://github.com/funny-bytes/chai-quantifiers
assertions chai unit-testing
Last synced: 5 months ago
JSON representation
Array quantifier assertions for chai.
- Host: GitHub
- URL: https://github.com/funny-bytes/chai-quantifiers
- Owner: funny-bytes
- Created: 2018-02-22T18:12:14.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-02-26T14:55:28.000Z (over 2 years ago)
- Last Synced: 2025-09-24T09:50:10.599Z (9 months ago)
- Topics: assertions, chai, unit-testing
- Language: JavaScript
- Homepage:
- Size: 506 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# chai-quantifiers
Array quantifier assertions for [Chai](http://chaijs.com/) assertion library.

[](https://coveralls.io/github/funny-bytes/chai-quantifiers?branch=master)
[](https://codeclimate.com/github/funny-bytes/chai-quantifiers/maintainability)
[]()
[](https://github.com/airbnb/javascript)
[](https://www.npmjs.com/package/chai-quantifiers)
[]()
## Install
```bash
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:
```javascript
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*.