PACKAGE · TESTING

chai

BDD/TDD assertion library for node.js and the browser. Test framework agnostic.

WEEKLY DOWNLOADS 216.8M
STARS 8.3K
FORKS 737
OPEN ISSUES 29
GZIP SIZE 17.3 kB
UNPACKED SIZE 149.5 kB
DEPENDENCIES 1
LAST UPDATED 10mo ago
DOWNLOAD TRENDS

chai downloads · last 12 months

Download trends for chai1 download series from Nov 2025 to Oct 2026. Use left and right arrow keys to inspect monthly values.0170.5M341.0M511.5M682.0MNov 2025FebMayAugOct 2026
chai
ABOUT CHAI

Chai is a JavaScript assertion library for Node.js and browsers. It provides readable checks for test expectations, such as comparing values or verifying object properties, so tests can report clearly which conditions passed or failed without embedding assertion logic in application code.

Chai supports both behavior-driven development and test-driven development, while remaining independent of any particular test framework. Its design gives developers a choice of assertion style rather than requiring one syntax, making it suitable for teams that prefer expressive, sentence-like checks as well as those who want a more direct assertion interface.

The main APIs are `expect`, `should`, and `assert`. With `expect`, a test can express a condition as a chain such as `expect(value).to.equal(expected)`; `should` offers a property-oriented style, and `assert` provides direct assertion functions. These APIs let a project choose a consistent style for checking values and properties across its test suite.

Chai fits into Node.js or browser JavaScript testing workflows and can be paired with a test runner of the developer’s choice. Because it is test-framework agnostic, teams can use its assertions without adopting a particular runner or changing the framework that discovers and executes their tests.

Chai 6.3.0 is MIT-licensed and has a reported gzip bundle size of 17.3 kB, with an unpacked size of 149.5 kB. Its 60.3M weekly downloads and 8.3K GitHub stars indicate substantial usage; the package metadata also reports 100 open issues and a last update date of 2026-10-19.

Chai supplies assertions, not test discovery, execution, or test isolation, so those responsibilities remain with the chosen testing setup. Its three assertion interfaces offer choice, but teams should select and document one style to keep test code consistent; projects seeking a complete test runner will need additional tooling.

WHEN TO USE
  • When writing Node.js or browser tests and you want assertions without coupling them to a specific test framework.
  • When expressing expected values in a readable BDD style, use `expect(value).to.equal(expected)` in test cases.
  • When a team prefers property-oriented assertion syntax, use Chai’s `should` interface and apply it consistently across tests.
  • When you want direct assertion functions, use the `assert` API for explicit checks in test code.
  • When adopting either a BDD or TDD workflow, use Chai to express the conditions each test must verify.
  • When retaining an existing test runner but standardizing assertion syntax, add Chai without replacing the runner’s test discovery and execution features.
WHEN NOT TO USE
  • If your requirement is a complete test runner with test discovery and execution, choose a testing tool that provides those features; Chai supplies assertions only.
  • If your project needs assertions but has a strict dependency or bundle budget below the reported 17.3 kB gzip size, evaluate a lighter assertion approach before adding Chai.
  • If the project requires a single fixed assertion syntax and does not want to choose among `expect`, `should`, and `assert`, use an assertion tool with only the required interface or standardize a wrapper around one Chai API.
  • If your tests are not written in JavaScript for Node.js or the browser, Chai’s stated runtime scope may not fit; use an assertion library intended for that environment.
  • If you need test execution, isolation, or discovery from the assertion dependency itself, use a test framework that includes those capabilities alongside assertions.

CORRECTIONS

Spot wrong data here?

A short note helps us fix it.

Anonymous · No account · No email back

COMPARISONS 11
chai vs nightwatch ★ 12.0K · 131.8K/wk chai vs fast-check ★ 5.3K · 75.4M/wk chai vs jest ★ 45.5K · 62.1M/wk chai vs jasmine-core ★ 15.8K · 6.3M/wk chai vs selenium-webdriver ★ 34.6K · 2.1M/wk chai vs mocha ★ 22.9K · 14.5M/wk chai vs @testing-library/react ★ 19.7K · 98.8M/wk chai vs ava ★ 20.8K · 593.9K/wk chai vs cypress ★ 51.0K · 7.5M/wk chai vs playwright ★ 101.1K · 178.1M/wk chai vs vitest ★ 17.5K · 189.7M/wk