{"id":25172,"library":"dirty-chai","title":"dirty-chai","description":"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.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/joshperry/dirty-chai","tags":["javascript","chai","chai-plugin","browser","testing"],"install":[{"cmd":"npm install dirty-chai","lang":"bash","label":"npm"},{"cmd":"yarn add dirty-chai","lang":"bash","label":"yarn"},{"cmd":"pnpm add dirty-chai","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; the plugin extends Chai's assertion chain","package":"chai","optional":false}],"imports":[{"note":"ESM is the default module system since v3","wrong":"const dirtyChai = require('dirty-chai')","symbol":"dirtyChai","correct":"import dirtyChai from 'dirty-chai'"},{"note":"Use ESM import for consistency with dirty-chai","wrong":"const chai = require('chai')","symbol":"chai","correct":"import chai from 'chai'"},{"note":"Plugin function must not be called; pass the function itself, not the result","wrong":"chai.use(dirtyChai())","symbol":"use","correct":"chai.use(dirtyChai)"}],"quickstart":{"code":"import chai from 'chai';\nimport dirtyChai from 'dirty-chai';\n\nchai.use(dirtyChai);\n\nconst { expect } = chai;\n\nexpect(true).to.be.true();\nexpect(null).to.be.null('Custom error message');\nexpect([1]).to.be.empty();\nexpect('hello').to.exist();\n\n// With chai-as-promised:\n// import chaiAsPromised from 'chai-as-promised';\n// chai.use(chaiAsPromised);\n// chai.use(dirtyChai);","lang":"typescript","description":"Import and use dirty-chai with ESM, demonstrating function-call form for common assertions and custom error messages."},"warnings":[{"fix":"Update chai to version >=6.2.0 <7","message":"dirty-chai 3.x requires Chai >= 6.2.0. Using older Chai versions will cause errors.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always terminate chains with a function call, e.g., .true()","message":"After dirty-chai, assertions must always be called with parentheses to execute. Syntactically correct without parens but assertion won't run.","severity":"gotcha","affected_versions":">=0"},{"fix":"Use .length or .arguments first in the chain, or separate into multiple assertions","message":"Chaining after .length or .arguments fails: these properties become functions and cannot be chained after other assertions.","severity":"gotcha","affected_versions":">=0"},{"fix":"Load chai-as-promised before dirty-chai, and dirty-chai before any other plugins","message":"Plugin must be loaded after chai-as-promised (if used), but before other plugins to transform their property assertions.","severity":"gotcha","affected_versions":">=0"},{"fix":"Use import dirtyChai from 'dirty-chai' instead of require('dirty-chai')","message":"CommonJS require is deprecated in v3; use ESM imports.","severity":"deprecated","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install dirty-chai and call chai.use(dirtyChai) before using function-form assertions.","cause":"dirty-chai not installed or not used with chai.use()","error":"TypeError: expect(...).to.be.true is not a function"},{"fix":"Add parentheses to the assertion: .true() instead of .true","cause":"Assertion called without parentheses, returning the function instead of executing it","error":"AssertionError: expected [Function] to be true"},{"fix":"Use .length first in the chain or break into separate assertions.","cause":"Attempting to chain .length after another assertion (e.g., .exist.and.have.length)","error":"Error: length is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}