Notice: The Monaca & Onsen UI Community Forum is shutting down.

For Onsen UI bug reports, feature requests and questions, please use the Onsen UI GitHub issues page. For help with Monaca, please contact Monaca Support Team.

Thank you to all our community for your contributions to the forum. We look forward to hearing from you in the new communication channels.

Mocha + Chai.js unit testing for ES6 with Istanbul code coverage

  • Onsen UI

    Chai and mocha

    Testing is very important for finding bugs, verifying the functionality and improving the general stability of a piece of software. Almost all (if not all) developers test their code in some way. One way to test would be to manually run the program and try out all the functions to see if everything is working as expected. Another (and better) way is to write automated tests that are run every time the code changes.

    Click here to see the original article

  • Hi there! Very nice tutorial thank you!
    when I run the command

    ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha – --compilers js:babel/register

    the terminal throws error that “No coverage information was collected”. Do you ahve any suggestion why is this?

  • I’ve tried the coverage report generated by isparta. The report seems to be buggy, it’s not perfect: in files with 8 branches, isparta detected 33. So I’ve looked for an alternative and found the “istanbul@1.0.0-alpha.2” package. Just install it, replace the command and everything is alright. At least in my project :)

  • This article is a bit outdated since a lot of packages has changed. Mainly Babel has changed a lot since this was written.

    I plan on rewriting it at some point with the latest tools.

  • The official mocha site says:

    Passing arrow functions to Mocha is discouraged. Their lexical binding of the this value makes them unable to access the Mocha context, and statements like this.timeout(1000); will not work inside an arrow function.

  • Just looking for the same thing run in the browser, using ES6 classes, systemJS and Babel-plugin transpiler. Have you by any chance written that promised article?