Jest – Painless JavaScript Testing

jest

I’ve been hearing great things about Jest lately. It’s worth checking it out:

Jest is a JavaScript testing framework, used by Facebook to test all JavaScript code including React applications.

Install Jest using npm (along with some extra Babel presets if you’re writing ES2015 – Don’t forget to configure Babel using .babelrc to use the es2015 and react presets):

npm install --save-dev babel-jest babel-polyfill babel-preset-es2015 babel-preset-react jest

A simple – non-React – test is this (put it in a folder named __tests__):

describe('Addition', () => {
  it('knows that 2 and 2 make 4', () => {
    expect(2 + 2).toBe(4);
  });
});

As read in the description, you can also use it to test React components with it.

Jest – Painless JavaScript Testing →
Egghead: Getting started with Jest (Video) →
How to Test React Components Using Jest →
Jest 14.0: React Tree Snapshot Testing →

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.