Chai Things
raw JSON → 0.2.0 verified Sat Apr 25 auth: no javascript deprecated
Chai Things (v0.2.0, unmaintained since 2015) extends Chai assertion library with array element matchers like `include.something.that`, `all`, and `none`. Allows deep equality, property, and nested assertions on arrays. Last updated on npm in 2016; no releases for 9+ years. Use with Chai v4.x but may have compatibility issues. Alternative: use native Chai `members` matcher with deep equality or Lodash`_.some`/_.every.
Common errors
error TypeError: Cannot read property 'use' of undefined ↓
cause chai is not imported or chai.should() not called.
fix
Ensure you have required chai and called chai.should() or chai.expect before using chai-things.
error AssertionError: expected [] to include something that deeply equals ... ↓
cause Using something matcher on an empty array; no element matches.
fix
Check that array is not empty or use include.something.that on non-empty arrays.
error chai-things: Error: cannot call include.something.that on non-array value ↓
cause Attempting to use include.something.that on a non-array object.
fix
Ensure the value being tested is an Array.
Warnings
deprecated Package has not been updated since 2016. It may not work with Chai 5.x or newer. ↓
fix Consider using chai.assert.deepInclude or other native Chai methods, or migrate to a maintained library.
gotcha Cannot be used with ESM imports directly; only CommonJS require works reliably. ↓
fix Use dynamic import: const chaiThings = (await import('chai-things')).default;
breaking In Chai 4.x, 'should' interface requires chai.should() call before chai.use(require('chai-things')). ↓
fix Always call chai.should() earlier or use chai.expect with chai-things.
gotcha The 'all' and 'none' matchers treat empty arrays as vacuously true (all matches everything, none matches nothing). ↓
fix Add explicit length check if needed: arr.should.have.length.gt(0).and.all.satisfy(...).
Install
npm install chai-things yarn add chai-things pnpm add chai-things Imports
- default wrong
const chaiThings = require('chai-things'); chai.use(chaiThings);correctimport chaiThings from 'chai-things'; chai.use(chaiThings); - chai-things wrong
import { something } from 'chai-things';correctimport 'chai-things'; // side-effect import when used via chai.should() - Plugin usage wrong
const { Plugin } = require('chai-things');correctchai.use(require('chai-things')); // CommonJS
Quickstart
const chai = require('chai');
chai.should();
chai.use(require('chai-things'));
// Example:
const items = [{ a: 1 }, { b: 2 }];
items.should.include.something.that.deep.equals({ b: 2 });
// passes
items.should.all.have.property('a');
// fails because { b: 2 } does not have property 'a'
items.should.not.include.something.that.deep.equals({ c: 3 });
// passes