Chai is a BDD / TDD assertion library for node and the browser that can be paired with any JavaScript testing framework.
It provides a clean and readable syntax for writing test assertions.
A comprehensive cheat sheet for the Chai assertion library, covering various assertion styles and methods for effective testing in JavaScript.
Chai is a BDD / TDD assertion library for node and the browser that can be paired with any JavaScript testing framework. It provides a clean and readable syntax for writing test assertions. |
Chai supports several interfaces: |
Installation: |
Importing Chai:
|
The Basic Syntax: |
Example:
|
The Basic Syntax: |
Example:
|
|
Checks for deep equality (using |
|
Checks for deep equality of objects and arrays |
|
Alias for |
|
Checks the type of a value |
|
Alias for |
|
Checks if a value is not |
|
Checks if a value is |
|
Checks if a value is strictly |
|
Checks if a value is strictly |
|
Checks if a value is truthy |
|
Checks if |
|
Checks if |
|
Checks if |
|
Checks if |
|
Checks if |
|
Tests shallow, coercive equality with the equal comparison operator ( == ) |
|
Tests strict equality ( === ) |
|
Tests for deep equality |
|
Tests shallow, coercive inequality with the not equal comparison operator ( != ) |
|
Tests strict inequality ( !== ) |
|
Tests for deep inequality |
|
Tests if a value is truthy |
|
Tests if a value is falsy |
|
Tests if a value is strictly true |
|
Tests if a value is strictly false |
|
Tests if a value is not undefined |
|
Tests if a value is undefined |
|
Tests if a value is null |
|
Tests if a value is not null |
|
Tests if the type of value is as expected |
|
Tests if a value is greater than another value |
|
Tests if a value is less than another value |
|
Tests if a value is greater than or equal to another value |
|
Tests if a value is less than or equal to another value |
|
Checks if |
|
Alias for |
|
Checks if |
|
Asserts that |
|
Asserts that |
|
Checks if |
|
Alias for |
|
Checks if |
|
Asserts that object has expected length. |
|
Asserts that value is an array. |
|
Checks if |
|
Checks if |
|
Checks if |
|
Asserts that object has property. |
|
Asserts that object has a deep property. |
|
Asserts that object has property with expected value. |