Chai Testing

Chai is a BDD/TDD assertion libraty for javascript testing framework

Lets build a simple application to test this

Install chai and mocha test runniner packages as dev dependencies

Now in test folder, we will be adding a simple test js file

Here we created a file named chaitest file in test folder.

The pattern for chai is

describe() – what group we are testing and can have nested describes for each feature

and for main parent we can set some values in before() and after() functions to execute something for once

And for child beforeEach() here it executes before each feature is completed. It means here after it() test function we can set a value here and it() describes the test.

to run test, use npm run test in terminal

You can see all the tests are passed

Code in my github: https://github.com/pbndru/phani.chai

Leave a comment