Chai

Chai is a BDD assertion library. Chai uses a fluent API to allow for extremely flexible assertions. The two most popular ways that Chai is used are through the should and expect interfaces provided. The way that Chai works, and in fact, the way that every testing frameworks assertion works, is by throwing an exception when the check done by the assertion fails.

For instance, if you had a variable named foo with a value 3 and your assertion was expect(foo).to.equal(5) when the test ran, that assertion would throw an exception with a message that says expected 3 to equal 5.

To install Chai into your project, run the following command:

>npm install chai

Once you have Chai installed, there is one more step that must be taken to be able to use it within your project. You must include the following import at the top of each test file in your application:

import { expect } from ‘chai’;

If you wish to use should assertions, you can either replace expect with should or add should inside the curly braces, separating it from expect with a comma.

For more information or to refer to the documentation, the Chai home page is https://chaijs.com.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.34.62