News

Jest 23, Facebook’s popular framework for testing React applications is now released

2 min read

A new version of Jest, the popular framework for testing React applications is now available. Jest is developed by Facebook and can be used for testing JavaScript functions, but is specifically aimed at React. Jest is a zero configuration testing platform with features such as snapshot testing, parallelized test runs, built-in code coverage reports, and instant feedback.

Jest 23 features major updates. Here are the top ones.

Babel and Webpack join the Jest community

Webpack saw their total test suite time reduced 6x from over 13 minutes to 2 minutes 20 seconds, after converting from Mocha to Jest 23 Beta.

Interactive Snapshot Mode

The newly incorporated Interactive snapshot mode, is added as a default watch menu option. With this new mode, testers can browse through each failing snapshot in each failing suite, and review, update or skip each failed snapshots individually.

Snapshot Property Matchers

Jest now has Snapshot property matchers through which testers can pass properties to the snapshot matcher which specify the structure of the data instead of the specific values. These property matchers are then verified before serializing the matcher type to provide consistent snapshot results across multiple test runs.

Jest Each

Jest 23 features a new jest-each library inspired by mocha-each and Spock Data Tables. This library defines a table of test cases, and then runs a test for each row with the specified column values. Support is provided for both array types and template literals for all flavors of describe and test.

Watch Mode Plugins

The watch mode system now allows adding of custom plugins to watch mode. These watch mode plugins can hook into Jest events and provide custom menu options in the watch mode menu.

Other changes include:

  • Test descriptions and functions are a mandate. Jest 23 will fail tests that do not include both a function and a description.
  • Undefined props from React snapshots are now removed.
  • MapCoverage, jest.genMockFunction and jest.genMockFn are deprecated.
  • Snapshot name (if provided) is now added to the snapshot failure message so it’s easier to find the snapshot that’s failing.
  • Mock timestamps are replaced with invocationCallOrder since two or more mocks may often have the same timestamp, making it impossible to test the call order.
  • Mock function call results are added to snapshots so that both the calls and the results of the invocation are tracked.

For the complete list of changes and updates, see the changelog.

Read next

Testing Single Page Applications (SPAs) using Vue.js developer tools
What is React.js and how does it work?
How to test node applications using Mocha framework

Sugandha Lahoti

Content Marketing Editor at Packt Hub. I blog about new and upcoming tech trends ranging from Data science, Web development, Programming, Cloud & Networking, IoT, Security and Game development.

Share
Published by
Sugandha Lahoti

Recent Posts

Top life hacks for prepping for your IT certification exam

I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…

3 years ago

Learn Transformers for Natural Language Processing with Denis Rothman

Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…

3 years ago

Learning Essential Linux Commands for Navigating the Shell Effectively

Once we learn how to deploy an Ubuntu server, how to manage users, and how…

3 years ago

Clean Coding in Python with Mariano Anaya

Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…

3 years ago

Exploring Forms in Angular – types, benefits and differences   

While developing a web application, or setting dynamic pages and meta tags we need to deal with…

3 years ago

Gain Practical Expertise with the Latest Edition of Software Architecture with C# 9 and .NET 5

Software architecture is one of the most discussed topics in the software industry today, and…

3 years ago