chai-parentheses

raw JSON →
0.0.2 verified Fri May 01 auth: no javascript

Chai plugin that converts terminating property assertions (true, false, null, etc.) into function-call form to avoid lint errors and ensure assertions are actually executed. v0.0.2 is the latest stable version, released as a maintenance fork of dirty-chai that works with modern bundlers (ESM/CJS compatibility). Key differentiator vs. dirty-chai: fixes bundler issues without changing API. Supports custom error messages and works with other Chai plugins when loaded first. Ships TypeScript types.

error Error: length is not a function
cause Using .length after another chained property assertion with parentheses
fix
Use .length first: myArray.should.have.length(3).and.should.exist()
error AssertionError: expected undefined to be truthy
cause Forgetting to call the terminating function; property assertion never executed
fix
Add parentheses: expect(true).to.be.true()
error TypeError: chai.use is not a function
cause Passing parentheses() to chai.use instead of the plugin reference
fix
Correct: chai.use(parentheses); not chai.use(parentheses());
breaking Chaining length/argument after other assertions breaks: myArray.should.exist.and.should.have.length(3) throws 'length is not a function'
fix Place length/arguments assertions first in chain or use separate assertion statements.
gotcha Plugin must be loaded after chai-as-promised but before other plugins that add property assertions
fix Load chai-as-promised first, then chai-parentheses, then other plugins like sinon-chai.
gotcha The chain must always be terminated with a function call; otherwise prior assertions in the chain may not execute
fix Always end with () for terminators: expect(true).to.be.true() or expect(true).to.be.true.and.not.false()
deprecated dirty-chai has known issues with modern bundlers (Webpack/Rollup); chai-parentheses is the recommended replacement
fix Replace dirty-chai with chai-parentheses in package.json and imports. API is identical.
npm install chai-parentheses
yarn add chai-parentheses
pnpm add chai-parentheses

Demonstrates importing and using chai-parentheses with Chai's expect, including function-call form for terminators.

import { expect, use } from 'chai';
import parentheses from 'chai-parentheses';

use(parentheses);

describe('example', () => {
  it('works', () => {
    expect(true).to.be.true();
    expect(null).to.be.null();
    expect({}).to.be.empty();
  });
});