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

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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here