{"id":10381,"library":"chai","title":"Chai Assertion Library","description":"Chai is a widely used BDD/TDD assertion library for both Node.js and browser environments, designed to be framework-agnostic and pair delightedly with any JavaScript testing framework. The current stable version is 6.2.2, with frequent patch and minor releases, alongside periodic major updates, demonstrating an active development cadence.","status":"active","version":"6.2.2","language":"javascript","source_language":"en","source_url":"https://github.com/chaijs/chai","tags":["javascript","test","assertion","assert","testing","chai"],"install":[{"cmd":"npm install chai","lang":"bash","label":"npm"},{"cmd":"yarn add chai","lang":"bash","label":"yarn"},{"cmd":"pnpm add chai","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"wrong":"const expect = require('chai').expect;","symbol":"expect","correct":"import { expect } from 'chai';"},{"wrong":"const assert = require('chai').assert;","symbol":"assert","correct":"import { assert } from 'chai';"},{"wrong":"import { should } from 'chai';","symbol":"should","correct":"import { should } from 'chai';\nshould();"}],"quickstart":{"code":"import { expect } from 'chai';\n\nconst add = (a, b) => a + b;\nconst isPositive = (num) => num > 0;\n\n// Basic assertions\nexpect(add(2, 3)).to.equal(5);\nexpect(add(-1, 5)).to.be.above(0);\nexpect(isPositive(10)).to.be.true;\n\n// Deep equality for objects\nexpect({ a: 1, b: 2 }).to.deep.equal({ a: 1, b: 2 });\n","lang":"javascript","description":"This quickstart demonstrates basic assertions using Chai's Expect style, including numerical comparisons, boolean checks, and deep object equality."},"warnings":[{"fix":"Update your imports to reference the main `chai` package directly, e.g., `import { expect } from 'chai';` instead of `import { expect } from 'chai/lib/expect';`.","message":"Chai v6.0.0 introduced a breaking change where direct imports from internal `lib/*.js` files are no longer supported. The library is now bundled into a single `index.js`.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"After `import { should } from 'chai';`, add `should();` on the next line.","message":"When using Chai's `should` assertion style, you must explicitly call `should()` after importing it to extend `Object.prototype` and enable the assertion syntax.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefer importing assertion styles locally (e.g., `import { expect } from 'chai';`) to avoid global pollution and ensure better test isolation.","message":"Importing a Chai assertion style globally (e.g., `import 'chai/register-expect';`) modifies the global scope. While convenient for quick setups, this can lead to unexpected side effects or conflicts in larger projects.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-18T00:00:00.000Z","next_check":"2026-07-17T00:00:00.000Z","problems":[{"fix":"Change the import path to `import { expect } from 'chai';` or `import { assert } from 'chai';`.","cause":"Attempting to import internal `lib/*.js` files directly after Chai v6.0.0, which bundled the library into a single `index.js`.","error":"Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'chai/lib/expect' imported from ..."},{"fix":"Add `should();` immediately after the import statement: `import { should } from 'chai'; should();`.","cause":"Using Chai's `should` assertion style without calling `should()` after importing it, which is necessary to extend `Object.prototype`.","error":"TypeError: (0 , chai__WEBPACK_IMPORTED_MODULE_0__.should) is not a function"},{"fix":"Update your code to use ESM `import` statements, for example, `import { expect } from 'chai';` instead of `const expect = require('chai').expect;`.","cause":"Attempting to use the CommonJS `require` function in an ECMAScript Module (ESM) file context (e.g., a `.mjs` file or a project with `\"type\": \"module\"` in `package.json`).","error":"ReferenceError: require is not defined"}],"ecosystem":"npm"}