Use Karma, Mocha, Chai and Coverage to run headless unit tests and generate lcov code coverage

Loading

Reading Time: 3 minutesGithub: https://github.com/railsstudent/image-gallery-native-js 1) Install gulp, mocha, chai, puppeteer, http-server as dev-dependencies yarn add gulp mocha chai puppeteer http-server -D 2) Install all karma dependencies as dev-dependencies. yarn add karma karma-chai karma-mocha karma-chrome-launcher mocha chai -D 3) Create test/bootstrap.karma.js file to share global variables among unit test cases. ‘use strict’; const expect = chai.expect; const assert … Read more

Automate UI testing with Mocha and Puppeteer (Updated)

Loading

Reading Time: 2 minutesGithub: https://github.com/railsstudent/image-gallery-native-js 1) yarn add puppeteer mocha chai yarn add puppeteer mocha chai 2) Create bootstrap.js file to share global variables among tests. Expose chai.expect, chai.assert and an instance of browser ‘use strict’; const puppeteer = require(‘puppeteer’); const chai = require(‘chai’); const expect = chai.expect; const globalVariables = { browser: global.browser, expect: global.expect }; // … Read more