Registry / testing / chai-parentheses

chai-parentheses

JSON →
library0.0.2jsnpmunverified

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.

npm install chai-parentheses
INSTALL
IMPORT
SIG · CHAI-PARENTHESES
C
chai-parentheses
testingjavascriptv0.0.2
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.

default
import parentheses from 'chai-parentheses'
const parentheses = require('chai-parentheses')
Default export is the plugin function. CJS require also works in Node.
chai.use
import { use } from 'chai'; use(parentheses)
chai.use(parentheses())
Do not call parentheses as a function; pass the plugin reference.
expect().to.be.true
expect(true).to.be.true()
expect(true).to.be.true
After using chai-parentheses, terminate with () for assertions like true, false, null, undefined, exist, empty, ok, arguments.

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(); }); });
Debug
Known issues
breakingChaining 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.
affects: >=0.0.0
gotchaPlugin 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.
affects: >=0.0.0
gotchaThe 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()
affects: >=0.0.0
deprecateddirty-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.
affects: >=0.0.0
Errors
Common errors & fixes
Error: length is not a function
Using .length after another chained property assertion with parentheses
fix
Use .length first: myArray.should.have.length(3).and.should.exist()
AssertionError: expected undefined to be truthy
Forgetting to call the terminating function; property assertion never executed
fix
Add parentheses: expect(true).to.be.true()
TypeError: chai.use is not a function
Passing parentheses() to chai.use instead of the plugin reference
fix
Correct: chai.use(parentheses); not chai.use(parentheses());
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies
chairequiredpeer dependency - plugin requires Chai to be installed
Agent activity
9 hits · last 30 days
node
6
OpenAI (training)
1
Resources
chai-parentheses — npm install chai-parentheses · libregistry