Testing frameworks in javascript

JS testing tools are mentioned below.
  • Puppeteer
  • Cucumber JS
  • Webdriver IO
  • Cypress
  • Jest
  • Mocha


Mocha is a unit testing framework. Main features of Mocha are
  • test framework for Node.js
  • works with any assertion library
  • run tests using mocha command. By default, it will look for tests under test directory
  • Asynchronous testing with promises
  • Test coverage reporting
  • Test retry support
  • Test duration report
  • run tests matching regular expressions
  • before and after hooks
  • run tests from command line

npm install --save-dev mocha chai mochawesome mocha-parallel-tests

var expect = require('chai').expect;
var should = require('chai').should();
var assert = require('chai').assert;
describe('Simple feature',function () {
      it('Check sagar length',function() {
           var len =   "sagar".length;


       before(function() {
           console.log("Before file")
       after(function() {
           console.log("After file")
       beforeEach(function() {
           console.log("Before each test")
       afterEach(function() {
           console.log("After each test")


//Run tests

npx mocha "xyz/**/*.js"
npx mocha-parallel-tests
npx mocha --reporter xunit --reporter-option output=report.xml


Install using npm i jest --save-devBy default, Jest expects to find test files in a folder called tests in your project folder. Create the new folder:

describe("Length function", () => {
  test("Check string length", () => {
          var len =   "sagar".length;                 
            //return expect(fetchData()).resolves.toBe('peanut butter');


//async code
test('the data is peanut butter', async () => {
const data = await fetchData();
expect(data).toBe('peanut butter');


//Run tests
npx jest


  • Install npm i cypress
  • cypress.json file should be in root
  • Keep tests in cypress\integration
  • Run tests npx cypress run

describe("Form test", () => {
  it("Can fill the form", () => {

Cucumber JS

  • npm init
  • npm install @cucumber/cucumber
  • create features dir and add scenarios in it
  • Cucumber.js - config file
  • Add step def file under feature directory
  • Run tests using npx cucumber-js

const { Before, Given, When, Then } = require('@cucumber/cucumber')
let x
Given('I buy drilling tool worth ${int}', function (int) {
  x = int


  • Puppeteer uses devtools protocol to automate chrome browser
  • Install using npm i puppeteer

   const puppeteer = require('puppeteer');

   async function run () {
       const browser = await puppeteer.launch({headless:true});
       const page = await browser.newPage();
       await page.goto("https://www.softpost.org");
       await page.screenshot({path: 'screenshot.png'});


Chai is an assertion library in JavaScript. Chai is usually used with Mocha. Main features of Chai are
  • BDD assertion style using Expect and Should
  • TDD assertion style using Assert


Jasmine is BDD framework for JavaScript. Main features of Jasmine are
  • BDD style tests
  • Built in assertion library
  • run tests from command line
  • comes with test doubles library

Web development and Automation testing

solutions delivered!!