• Stars
    star
    104
  • Rank 330,604 (Top 7 %)
  • Language
    CoffeeScript
  • License
    Other
  • Created almost 12 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Chai support for assertions on array elements

Chai Things

Chai Things adds support to Chai for assertions on array elements.

Examples

Something

Use the something property on an array to test whether the assertion holds for one of its elements.

// Although they are equal, two different { a: 'cat' } objects are not the same
[{ a: 'cat' }, { a: 'dog' }].should.not.include({ a: 'cat' })
// Chai Things allows us to test deep equality on one of the elements
[{ a: 'cat' }, { a: 'dog' }].should.include.something.that.deep.equals({ a: 'cat' })
// If the test fails, we get a descriptive message
[{ a: 'cat' }, { a: 'dog' }].should.include.something.that.deep.equals({ a: 'cow' })
/* expected an element of [ { a: 'cat' }, { a: 'dog' } ] to deeply equal { a: 'cow' } */

You are free to choose the syntactic variant you like most:

[4, 11, 15].should.include.one.below(10)
[4, 11, 15].should.contain.some.above(10)
[4, 11, 15].should.not.contain.any.above(20)
[{ a: 'cat' }, { a: 'dog' }].should.contain.a.thing.with.property('a', 'cat')
[{ a: 'cat' }, { a: 'dog' }].should.contain.an.item.with.property('a', 'dog')

All

Use the all property on an array to test whether the assertion holds for all its elements.

// All items are below 20
[4, 11, 15].should.all.be.below(20)
// All items have a property 'a'
[{ a: 'cat' }, { a: 'dog' }].should.all.have.property('a')
// If the test fails, we get a descriptive message
[4, 11, 15].should.all.be.above(20)
/* expected all elements of [ 4, 11, 15 ] to be above 20 */
[{ a: 'cat' }, { a: 'dog' }].should.all.have.property('a', 'cat')
/* expected all elements of [ { a: 'cat' }, { a: 'dog' } ] to have a property 'a' of 'cat', but got 'dog' */

There are currently no syntactic variants for all. Let me know if you need them.

Installation and usage

$ npm install chai-things
var chai = require("chai");
chai.should();
chai.use(require('chai-things'));

Known issues

Because of how Chai works internally, it is not possible to combine Chai Things in certain ways. (See #4 and #9.)

More Repositories

1

chai

BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
JavaScript
8,128
star
2

chai-as-promised

Extends Chai with assertions about promises.
JavaScript
1,421
star
3

sinon-chai

Extends Chai with assertions for the Sinon.JS mocking framework.
JavaScript
1,089
star
4

chai-http

HTTP Response assertions for the Chai Assertion Library.
JavaScript
634
star
5

chai-jquery

jQuery assertions for chai
JavaScript
372
star
6

chai-spies

Spies for Chai Assertion Library.
JavaScript
132
star
7

type-detect

Improved typeof detection for node.js and the browser.
JavaScript
130
star
8

deep-eql

Improved deep equality testing for Node.js and the browser.
JavaScript
108
star
9

chai-json-schema

Chai plugin for JSON Schema v4
JavaScript
75
star
10

chaijs.github.io

The chaijs.com website source code. Contributions welcome.
JavaScript
49
star
11

pathval

Object value retrieval given a string path
JavaScript
42
star
12

chai-fs

Chai assertions for Node.js filesystem
JavaScript
33
star
13

assertion-error

Error constructor for test and validation frameworks that implements standardized AssertionError specification.
TypeScript
25
star
14

chai-factories

Factories over fixtures. Chai Assertion Library.
JavaScript
23
star
15

loupe

Inspect utility for Node.js and browsers
JavaScript
21
star
16

chai-stats

Statistical and additional numerical assertions for the Chai Assertion Library.
JavaScript
16
star
17

check-error

Error comparison and information related utility for node and the browser
JavaScript
14
star
18

chai-change

Assert that a change you expected to happen, happened, with this chai plugin
JavaScript
14
star
19

get-func-name

Reliably get the name of a Function in a cross-browser compatible way.
JavaScript
12
star
20

simple-assert

Vanilla Assertions
JavaScript
7
star
21

chai-null

Null Object Pattern implementation for the Chai Assertion Library
JavaScript
5
star
22

chai-timers

Timers, stopwatches, and other time based assertions for the Chai Assertion Library.
JavaScript
5
star
23

guidelines

Guidelines for the Chaijs Organisation
1
star
24

plugin-use

A simple Event Emitter, tuned to be used as a plugin driver.
TypeScript
1
star