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 →

Elsewhere , , , ,

One Response to Jest – Painless JavaScript Testing

  1. Pingback: Automatically rerun PHPUnit tests when source code changes with phpunit-watcher | Bram.us

Leave a Reply

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