Need advice about which tool to choose?Ask the StackShare community!

Jasmine

2.5K
1.5K
+ 1
186
Jest

9.1K
3.8K
+ 1
175
Add tool

Jasmine vs Jest: What are the differences?

Jasmine and Jest are popular testing frameworks used in JavaScript development. While they share some similarities, there are several key differences between them that set them apart. Here are six specific differences:

  1. Installation: Jasmine requires manual installation as a standalone library, which involves downloading and adding it to your project. On the other hand, Jest comes pre-packaged with Create React App and can be easily integrated into your project without any additional installation steps.

  2. Syntax: When it comes to syntax, there are notable differences between Jasmine and Jest. Jasmine uses a more traditional and verbose syntax with nested describe and it blocks, whereas Jest provides a more streamlined and concise syntax with methods like test and expect.

  3. Mocks and Spies: While both frameworks allow you to create mocks and spies to test function behavior, Jest provides built-in support for mocks and spies out of the box. Jest's jest.fn() allows you to easily mock functions and track their calls, whereas in Jasmine, you need to use separate libraries like Sinon or Jasmine-SpyObj to achieve similar functionality.

  4. Snapshot Testing: Snapshot testing is a powerful feature offered by Jest that allows you to capture and compare the output of your components or functions with previously saved snapshots. This can be particularly useful when testing UI components. Jasmine, on the other hand, does not have built-in support for snapshot testing, although it can be achieved with additional libraries.

  5. Parallel Testing: When it comes to parallel testing, Jest has a distinct advantage over Jasmine. Jest is designed to run test suites in parallel, making it much faster when you have a large number of tests. Jasmine, on the other hand, does not have built-in support for parallel testing and runs tests sequentially.

  6. Code Coverage: Both Jasmine and Jest provide code coverage reports, but Jest's code coverage tools are more advanced and powerful. Jest's coverage report includes detailed information such as line, statement, and branch coverage, making it easier to identify areas of your code that need further testing. Jasmine's coverage report is relatively simpler and provides less detailed information.

In summary, Jasmine and Jest have some similarities but also significant differences. Jest offers a simpler installation process, a more streamlined syntax, built-in support for mocks and spies, snapshot testing, better parallel testing, and more advanced code coverage tools. Consider your specific project requirements and preferences to choose the framework that best suits your needs.

Decisions about Jasmine and Jest
Ben Herbert
Lead Front End Developer at Crunch · | 4 upvotes · 43.8K views

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.

See more
Shared insights
on
CypressCypressJestJest

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
Get Advice from developers at your company using StackShare Enterprise. Sign up for StackShare Enterprise.
Learn More