Chai: Assertions for Readable JavaScript Tests
Chai makes your JavaScript tests read like sentences. It provides assertion styles like `expect(value).to.equal(5)` to verify code behavior in test frameworks like Mocha. The main footgun: the `should` style fails silently on null or undefined values.
Chai is an assertion library that makes your JavaScript tests read like sentences. Instead of manual checks, you use expressive styles like `expect(value).to.equal(5)` or `value.should.equal(5)`. It pairs with any test runner like Mocha or Jest to verify your code's output and state. The most common footgun is using the `should` style, which fails silently on `null` or `undefined` variables because it can't be attached to them; `expect` is generally safer.
Read the original → chaijs.com
- #testing
- #javascript
- #nodejs
- #tdd
- #bdd
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.