What is mocha?
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases.
What are mocha's main functionalities?
Test Organization
Organize tests in suites and sub-suites using describe() and context(), and specify test cases using it().
"use strict";\nconst assert = require('assert');\ndescribe('Array', function() {\n describe('#indexOf()', function() {\n it('should return -1 when the value is not present', function() {\n assert.equal([1, 2, 3].indexOf(4), -1);\n });\n });\n});
Asynchronous Testing
Support for testing asynchronous code with ease, using callbacks, promises, or async/await.
"use strict";\nconst assert = require('assert');\ndescribe('User', function() {\n describe('#save()', function() {\n it('should save without error', function(done) {\n const user = new User('Luna');\n user.save(function(err) {\n if (err) done(err);\n else done();\n });\n });\n });\n});
Hooks
Lifecycle hooks such as before(), after(), beforeEach(), and afterEach() for setting up preconditions and clean-up after tests.
"use strict";\ndescribe('Connection', function() {\n before(function() {\n // runs once before the first test in this block\n });\n\n after(function() {\n // runs once after the last test in this block\n });\n\n beforeEach(function() {\n // runs before each test in this block\n });\n\n afterEach(function() {\n // runs after each test in this block\n });\n\n // test cases\n});
Other packages similar to mocha
jest
Jest is a delightful JavaScript Testing Framework with a focus on simplicity. It works out of the box for any React project and is often compared to Mocha for its comprehensive feature set including a built-in assertion library and mock functions.
jasmine
Jasmine is a behavior-driven development framework for testing JavaScript code. It does not rely on browsers, DOM, or any JavaScript framework. Thus, it's suited for websites, Node.js projects, or anywhere that JavaScript can run. It's compared to Mocha for its clean syntax and testing capabilities.
ava
AVA is a test runner for Node.js with a concise API, detailed error output, and process isolation that lets you develop with confidence. It is often compared to Mocha for its modern, concurrent testing features, but differs in its approach to running tests in parallel by default.
Mocha is a simple, flexible, fun JavaScript test framework for node.js and the browser. For more information view the documentation.
Contributors
project : mocha
repo age : 2 years, 4 months ago
commits : 1314
active : 372 days
files : 141
authors :
582 TJ Holowaychuk 44.3%
389 Tj Holowaychuk 29.6%
46 Travis Jeffery 3.5%
31 Guillermo Rauch 2.4%
13 Attila Domokos 1.0%
10 John Firebaugh 0.8%
8 Jo Liss 0.6%
7 Nathan Rajlich 0.5%
6 Mike Pennisi 0.5%
6 James Carr 0.5%
6 Brendan Nee 0.5%
5 Aaron Heckmann 0.4%
5 Ryunosuke SATO 0.4%
4 hokaccha 0.3%
4 Joshua Krall 0.3%
4 Xavier Antoviaque 0.3%
3 Jesse Dailey 0.2%
3 Forbes Lindesay 0.2%
3 Sindre Sorhus 0.2%
3 Cory Thomas 0.2%
3 Fredrik Enestad 0.2%
3 Ben Lindsey 0.2%
3 Tyson Tate 0.2%
3 Mathieu Desvé 0.2%
3 Valentin Agachi 0.2%
3 Wil Moore III 0.2%
3 Merrick Christensen 0.2%
3 eiji.ienaga 0.2%
3 fool2fish 0.2%
3 Nathan Bowser 0.2%
3 Paul Miller 0.2%
2 Juzer Ali 0.2%
2 Pete Hawkins 0.2%
2 Jonas Westerlund 0.2%
2 Arian Stolwijk 0.2%
2 Quang Van 0.2%
2 Glen Mailer 0.2%
2 Justin DuJardin 0.2%
2 FARKAS Máté 0.2%
2 Raynos 0.2%
2 Michael Riley 0.2%
2 Michael Schoonmaker 0.2%
2 Domenic Denicola 0.2%
2 Simon Gaeremynck 0.2%
2 Konstantin Käfer 0.2%
2 domenic 0.2%
2 Paul Armstrong 0.2%
2 fcrisci 0.2%
2 Alexander Early 0.2%
2 Shawn Krisman 0.2%
2 Brian Beck 0.2%
2 Nathan Alderson 0.2%
2 David Henderson 0.2%
2 Timo Tijhof 0.2%
2 Ian Storm Taylor 0.2%
2 travis jeffery 0.2%
1 Matt Smith 0.1%
1 Matthew Shanley 0.1%
1 Nathan Black 0.1%
1 Phil Sung 0.1%
1 R56 0.1%
1 Refael Ackermann 0.1%
1 Richard Dingwall 0.1%
1 Romain Prieto 0.1%
1 Roman Neuhauser 0.1%
1 Roman Shtylman 0.1%
1 Russ Bradberry 0.1%
1 Russell Munson 0.1%
1 Rustem Mustafin 0.1%
1 Salehen Shovon Rahman 0.1%
1 Sasha Koss 0.1%
1 Seiya Konno 0.1%
1 Simon Goumaz 0.1%
1 Standa Opichal 0.1%
1 Stephen Mathieson 0.1%
1 Steve Mason 0.1%
1 Tapiwa Kelvin 0.1%
1 Teddy Zeenny 0.1%
1 Tim Ehat 0.1%
1 Vadim Nikitin 0.1%
1 Victor Costan 0.1%
1 Will Langstroth 0.1%
1 Yanis Wang 0.1%
1 Yuest Wang 0.1%
1 abrkn 0.1%
1 airportyh 0.1%
1 badunk 0.1%
1 fengmk2 0.1%
1 grasGendarme 0.1%
1 lodr 0.1%
1 tgautier@yahoo.com 0.1%
1 traleig1 0.1%
1 vlad 0.1%
1 yuitest 0.1%
1 Adam Crabtree 0.1%
1 Andreas Brekken 0.1%
1 Andreas Lind Petersen 0.1%
1 Andrew Nesbitt 0.1%
1 Andrey Popp 0.1%
1 Arnaud Brousseau 0.1%
1 Atsuya Takagi 0.1%
1 Austin Birch 0.1%
1 Bjørge Næss 0.1%
1 Brian Lalor 0.1%
1 Brian M. Carlson 0.1%
1 Brian Moore 0.1%
1 Bryan Donovan 0.1%
1 Casey Foster 0.1%
1 ChrisWren 0.1%
1 Corey Butler 0.1%
1 Daniel Stockman 0.1%
1 Dave McKenna 0.1%
1 Di Wu 0.1%
1 Dmitry Shirokov 0.1%
1 Fedor Indutny 0.1%
1 Florian Margaine 0.1%
1 Frederico Silva 0.1%
1 Fredrik Lindin 0.1%
1 Gareth Murphy 0.1%
1 Gavin Mogan 0.1%
1 Glen Huang 0.1%
1 Greg Perkins 0.1%
1 Harry Brundage 0.1%
1 Herman Junge 0.1%
1 Ian Young 0.1%
1 Ivan 0.1%
1 JP Bochi 0.1%
1 Jaakko Salonen 0.1%
1 Jakub Nešetřil 0.1%
1 James Bowes 0.1%
1 James Lal 0.1%
1 Jason Barry 0.1%
1 Javier Aranda 0.1%
1 Jeff Kunkle 0.1%
1 Jeremy Martin 0.1%
1 Jimmy Cuadra 0.1%
1 Jonathan Creamer 0.1%
1 Jussi Virtanen 0.1%
1 Katie Gengler 0.1%
1 Kazuhito Hokamura 0.1%
1 Kirill Korolyov 0.1%
1 Koen Punt 0.1%
1 Laszlo Bacsi 0.1%
1 Liam Newman 0.1%
1 László Bácsi 0.1%
1 Maciej Małecki 0.1%
1 Mal Graty 0.1%
1 Marc Kuo 0.1%
1 Matt Robenolt 0.1%
Links