Need advice about which tool to choose? Ask the StackShare community!
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.
We were able to combine multiple tools with Jest and React Testing Library (e.g. sinon, enzyme, chai). Jest has powerful cli options and increased performance including from parallel testing processes. Migrating was reasonably straight forward as there is a code transformation script to do most of the leg work. Jest's documentation is excellent.
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.
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.
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.
Pros of Jest
-
35
-
31
-
23
-
19
-
15
-
13
-
8
-
7
-
6
-
6
-
3
-
2
-
1
-
1
-
0
-
0
Pros of Mocha
-
137
-
102
-
81
-
48
-
29
-
12
-
7
-
5
-
3
-
1
-
1
-
1
-
1
-
1
-
1
Sign up to add or upvote pros Make informed product decisions
Cons of Jest
-
3
-
3
-
3
-
2
-
2
-
2
-
2
-
2
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
0
Cons of Mocha
-
3
-
2
-
1