Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Jest 24 Improves TypeScript Support, Plans Migration to TypeScript

Jest 24 Improves TypeScript Support, Plans Migration to TypeScript

The Jest team recently released Jest version 24 of their JavaScript testing framework, which improves its support for TypeScript test authoring. The Jest team also announced plans to migrate their codebase from Flow to TypeScript in the near future.

Upgrading Jest to leverage Babel 7 provides Jest's initial improvements to TypeScript support, as Babel can parse and transform type syntax with @babel/preset-typescript. Because Babel only removes type annotations in its compilation to valid JavaScript, Jest does not type check TypeScript source code.

Jest users are encouraged to run ts-jest for type checking while testing. Users also need to configure the code transformer not to apply Babel to .ts and .tsx files. The Jest team explain that users may also run tsc or use a Jest runner to simultaneously transpile TypeScript while running tests.

With the migration from Flow to TypeScript, the Jest team is hopeful that even more contributors will get involved. A minor release with this change should land in 2019.

Jest 23 made a change where tests missing an implementation would throw instead of getting skipped. The Jest team explains that this change broke the workflow for many developers relying on the old behavior as a way to create a todo list for testing. Simen Bekkhus, developer at Folio and Jest contributor, explains:

In Jest 24, we are addressing this issue by adding an explicit test.todo (inspired by the excellent AVA), which will be printed separately in the test summary. It allows you to quickly sketch out which tests you want to write and in the future, an ESLint rule might even be able to warn you that you have forgotten to write out some tests.

Jest 24 makes significant improvements to assertion messages in order to not miss several regressions when making progress with development, making it easier to debug and fix issues.

Jest previously had issues with missing console.log statements in some scenarios, and Jest 24 resolves this issue.

Jest 24 introduces some breaking changes:

  • The upgrade to the Micromatch 3 dependency, which is stricter in its parsing of globs than version 2
  • Node.js 4 support has been removed, though may still get used by adding polyfills for features missing in Node.js 4
  • The behavior of serialization of mock functions in snapshots has changes that may break existing users
  • Jest no longer automatically injects regenerator-runtime; verify the Babel configuration for transpiling async functions if running into this issue

Users of Jest should view the Jest 24 changelog for a complete list of changes in this release.

While Jest has gained significant adoption, in part because it is the default test runner for React, there are many other testing solutions available.

AVA is a modern test runner that tests source code within Node.js. The Jest team credits AVA for the inspiration of several improvements.

One limitation with Jest is that it primarily runs test in Node.js targeting JSDom, though there are solutions to using it with Karma, Cypress, or other tools.

Intern is another alternative to Jest which is authored in TypeScript and provides unit, functional, performance, accessibility and other forms of testing against all browsers.

Jest is open source software available under the MIT license. Contributions and feedback are encouraged via the Jest GitHub project and should follow the Jest contribution guidelines and Facebook open source code of conduct. New contributors are also invited to watch the Jest architecture video.

Rate this Article