Registry / testing / dirty-chai

dirty-chai

JSON →
library3.0.0jsnpmunverified

A Chai plugin that converts terminating property assertions (e.g., .true, .ok) into function-call form (e.g., .true(), .ok()). This makes assertions lint-friendly (avoiding 'Expected an assignment or function call' warnings) and ensures assertions are actually invoked. Version 3.0.0 requires Chai >= 6.2.0 < 7. It works with browser and Node, and can adapt property assertions from other Chai plugins when loaded before them. Key differentiator: eliminates false positives from uninvoked property access.

npm install dirty-chai
INSTALL
IMPORT
SIG · DIRTY-CHAI
D
dirty-chai
testingjavascriptv3.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dirtyChai
import dirtyChai from 'dirty-chai'
const dirtyChai = require('dirty-chai')
ESM is the default module system since v3
chai
import chai from 'chai'
const chai = require('chai')
Use ESM import for consistency with dirty-chai
use
chai.use(dirtyChai)
chai.use(dirtyChai())
Plugin function must not be called; pass the function itself, not the result

Import and use dirty-chai with ESM, demonstrating function-call form for common assertions and custom error messages.

import chai from 'chai'; import dirtyChai from 'dirty-chai'; chai.use(dirtyChai); const { expect } = chai; expect(true).to.be.true(); expect(null).to.be.null('Custom error message'); expect([1]).to.be.empty(); expect('hello').to.exist(); // With chai-as-promised: // import chaiAsPromised from 'chai-as-promised'; // chai.use(chaiAsPromised); // chai.use(dirtyChai);
Debug
Known issues
breakingdirty-chai 3.x requires Chai >= 6.2.0. Using older Chai versions will cause errors.
fix
Update chai to version >=6.2.0 <7
affects: >=3.0.0
gotchaAfter dirty-chai, assertions must always be called with parentheses to execute. Syntactically correct without parens but assertion won't run.
fix
Always terminate chains with a function call, e.g., .true()
affects: >=0
gotchaChaining after .length or .arguments fails: these properties become functions and cannot be chained after other assertions.
fix
Use .length or .arguments first in the chain, or separate into multiple assertions
affects: >=0
gotchaPlugin must be loaded after chai-as-promised (if used), but before other plugins to transform their property assertions.
fix
Load chai-as-promised before dirty-chai, and dirty-chai before any other plugins
affects: >=0
deprecatedCommonJS require is deprecated in v3; use ESM imports.
fix
Use import dirtyChai from 'dirty-chai' instead of require('dirty-chai')
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: expect(...).to.be.true is not a function
dirty-chai not installed or not used with chai.use()
fix
Install dirty-chai and call chai.use(dirtyChai) before using function-form assertions.
AssertionError: expected [Function] to be true
Assertion called without parentheses, returning the function instead of executing it
fix
Add parentheses to the assertion: .true() instead of .true
Error: length is not a function
Attempting to chain .length after another assertion (e.g., .exist.and.have.length)
fix
Use .length first in the chain or break into separate assertions.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
chairequiredpeer dependency; the plugin extends Chai's assertion chain
Agent activity
4 hits · last 30 days
node
4
Resources
dirty-chai — npm install dirty-chai · libregistry