Javascript Frameworks: Mocha vs Jasmine vs Cucumber vs Serenity/JS

Javascript has been enabling browsers for years. NodeJS brought it to the server side. TypeScript has wrapped familiar object-oriented, statically-typed syntax around it. Anywhere you look, you’ll find Javascript: on the client, server, mobile, and embedded systems.

These are three most common testing frameworks used in JavaScript based automation frameworks.
Jasmine , Mocha , Cucumber , Serenity/JS are very popular.

Common Ground: BDD Tests
– At their core, Mocha and Jasmine both offer Behavior-Driven Design (BDD) tests
– The describe function defines a test suite. The it function implements the BDD method of describing the behavior that a function should exhibit.

Below is the comparison in all these frameworks wrt to features

  • Assertion library:
    • Cucumber JS: Need to be integrated with Cucumber-assert
    • Jasmine: Inbuilt
    • Mocha: Need to be integrated with different assertion libraries : Chai, should.js, expect.js, better-assert
    • Serenity: In-built (Screenplay Pattern)
  • Gerkin language support:
    • Cucumber JS: Inbuilt
    • Jasmine: Need to be integrated with Karma or Cucumber
    • Mocha: Need to be integrated with Mocha-Cakes or mocha-gherkin
    • Serenity: In-built (Serenity BDD)
  • Grouping/tagging of tests:
    • Cucumber JS: Yes
    • Jasmine: Yes
    • Mocha: Yes
    • Serenity: Yes
  • Test runner:
    • Cucumber JS: Command line
    • Jasmine: Command line
    • Mocha: Command line
    • Serenity: In-built
  • Reporting:
    • Cucumber JS: Intuitive reports using cucumber-html-reporter and multiple-cucumber-html-reporter libraries
    • Jasmine: Either cucumber reports can be generated or karma-jasmine-html-reporter or jasmine-pretty-html-reporter can be used, but these reports are less intuitive than Cucumber
    • Mocha: Mocha-simple-html-reporter and mochawesome can be used for reporting. Mochawesome reports are intuitive, just like cucumber reports
    • Serenity: In-Built
  • Documentation/Forums support:
    • Cucumber JS: Good
    • Jasmine: Good
    • Mocha: Good
    • Serenity: Good
  • Rerun of failed tests:
    • Cucumber JS: No inbuilt support for JS version of Cucumber
    • Jasmine: No inbuilt support
    • Mocha: Inbuilt support available
    • Serenity: In-Built
  • Highlight slow tests:
    • Cucumber JS: No support available
    • Jasmine: Can be implemented using jasmine-slow-reporter
    • Mocha: Inbuilt support available
    • Serenity: No
  • Asynchronous testing:
    • Cucumber JS: Easy
    • Jasmine: Difficult
    • Mocha: Easy
    • Serenity: Easy
  • Parallel execution:
    • Cucumber JS: Yes
    • Jasmine: Yes
    • Mocha: Yes
    • Serenity : yes
  • Plug-in support and extensibility:
    • Cucumber JS: Limited
    • Jasmine: Limited
    • Mocha: Good
    • Serenity: Good

– Jasmine has its own assertion library where as Mocha needs Chai library

– It has the should style, the expect style, and the assert style

Sinon Fake Server:
– One feature that Sinon has that Jasmine does not is a fake server. This allows you to setup fake responses to AJAX requests made for certain URLs.

Running Tests:
– Mocha comes with a command line utility that you can use to run tests.
– Jasmine however does not have a command line utility to run tests. There are test runners out there for Jasmine, and a very popular one is Karma by the Angular team. Karma also allows support for Mocha if you’d like to run your Mocha tests that way.

Click on the image to view in Full screen

Leave a Reply