Jestย vsย Mocha

Jest

2.9K
2K
+ 1
154
Mocha

3.3K
2.3K
+ 1
415
Add tool

Jest vs Mocha: What are the differences?

Testing frameworks are the backbone of testing the code you have worked hard on. A good testing framework allows testing the client-side code. Two popular contenders are Jest and Mocha. Jest is an open source testing framework developed by Facebook. Built into the popular create-react-app package, is faster and smoother to write idiomatic JavaScript tests. It has built-in mocking and assertion abilities while running tests in parallel, providing a smoother, faster test-run. One unique feature of Jest is it provides Snapshot testing for complete control over UI. Mocha provides developers with a base test framework, with options such as assertion, mocking, and spy libraries. It is one of the most flexible JavaScript testing libraries. The slight downside to Mocha is the additional setup and configuration required. Chai, the most popular open-source assertion library is used with Mocha.

Advice on Jest and Mocha
Ezra Fayet
Needs advice
on
React
Mocha
and
Jest

I released two React hooks on npm:

  • use-wizard, to handle multi-paths, multi-steps wizards

  • use-formidable, to handle big nested forms (cause we all know how painful they are.)

GitHub Link: https://github.com/use-wizard

  • Any advice on what I should do first to improve/bundle the packages? (At the moment, I have no linter, no minifier, no compression, no webpack; I went straight to the features and unit tests)

  • I am bundling it with commonjs, should I also bundle it for ECMA modules?

If anyone wants to join, you're more than welcome; this is beginner-friendly as there are many things to do anyway.

See more
Decisions about Jest and Mocha
Shared insights
on
Jest
Cypress

As we all know testing is an important part of any application. To assist with our testing we are going to use both Cypress and Jest. We feel these tools complement each other and will help us get good coverage of our code. We will use Cypress for our end to end testing as we've found it quite user friendly. Jest will be used for our unit tests because we've seen how many larger companies use it with great success.

See more

Postman will be used to do integration testing with the backend API we create. It offers a clean interface to create many requests, and you can even organize these requests into collections. It helps to test the backend API first to make sure it's working before using it in the front-end. Jest can also be used for testing and is already embedded into React. Not only does it offer unit testing support in javascript, it can also do snapshot testing for the front-end to make sure components are rendering correctly. Enzyme is complementary to Jest and offers more functions such as shallow rendering. UnitTest will be used for Python testing as it is simple, has a lot of functionality and already built in with python. Sentry will be used for keeping track of errors as it is also easily integratable with Heroku because they offer it as an add-on. LogDNA will be used for tracking logs which are not errors and is also a Heroku add-on. Its good to have a separate service to record logs, monitor, track and even fix errors in real-time so our application can run more smoothly.

See more

We use Mocha for our FDA verification testing. It's integrated into Meteor, our upstream web application framework. We like how battle tested it is, its' syntax, its' options of reporters, and countless other features. Most everybody can agree on mocha, and that gets us half-way through our FDA verification and validation (V&V) testing strategy.

See more
Pros of Jest
Pros of Mocha

Sign up to add or upvote prosMake informed product decisions

Cons of Jest
Cons of Mocha

Sign up to add or upvote consMake informed product decisions

What is Jest?

Jest provides you with multiple layers on top of Jasmine.

What is Mocha?

Mocha is a feature-rich JavaScript test framework running on node.js and 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 companies use Jest?
What companies use Mocha?

Sign up to get full access to all the companiesMake informed product decisions

What tools integrate with Jest?
What tools integrate with Mocha?

Sign up to get full access to all the tool integrationsMake informed product decisions

Blog Posts

What are some alternatives to Jest and Mocha?
Selenium
Selenium automates browsers. That's it! What you do with that power is entirely up to you. Primarily, it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well.
AVA
Even though JavaScript is single-threaded, IO in Node.js can happen in parallel due to its async nature. AVA takes advantage of this and runs your tests concurrently, which is especially beneficial for IO heavy tests. In addition, test files are run in parallel as separate processes, giving you even better performance and an isolated environment for each test file.
Enzyme
Enzyme is a JavaScript Testing utility for React that makes it easier to assert, manipulate, and traverse your React Components' output.
Jasmine
Jasmine is a Behavior Driven Development testing framework for JavaScript. 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.
Cypress
Cypress is a front end automated testing application created for the modern web. Cypress is built on a new architecture and runs in the same run-loop as the application being tested. As a result Cypress provides better, faster, and more reliable testing for anything that runs in a browser. Cypress works on any front-end framework or website.
See all alternatives
Interest over time