In this post we are going to review the following topics
Assertions
What is an assertion? Is an expression which encapsulates some testable logic specified about a target under test. - Is always True OR False.
Chai is clasified into two:
BDD - Behavior-driven development language, is an expressive language in a readable style. TDD - Test-driven development, more classical feel.
mkdir /path/to/newfolder
node -v #verify node version
npm -v #verify npm version
npm install chai -save-dev #install chai
Import Chai to project adding the following code
const chai = require('chai');
And run from the terminal
npm test/myfile.js
See code.
Expect vs Should vs Assert
Manage undefined with should
// normal scenario
error.should.not.exist();
// given that error is undefined
should.not.exist(error);
Configurations
chai.config.showDiff = false; // turn off reported diff display
chai.config.truncateThreshol = 0; // disable truncating
chai.config.includeStack = true; // turn on stack trace
Install Chai using npm install chai -save-dev
Add Chai variables
const chai = require('chai');
const assert = chai.assert;
const expect = chai.expect;
const should = chai.should();
Thats the end of the introduction. You should be able to start working from here. Next step will be combining it with an automation framework, like Selenium.