Infinite Jest

Unit Testing with the Jest Framework

- Greg Douglas

What is Jest?

  • A unit testing framework
  • Developed by Facebook
  • Originally based on Jasmine
  • Similar syntax to Jasmine/Mocha

Why use Jest?

  • It is FAST
  • Configuration is easy
  • It has a great CLI and watch mode
  • Clear and concise error messages
  • Supports ES6 natively
  • Built with React in mind

Walkthrough

Comparison to Chai Expect

const { expect } = require('chai');

describe('foo', function() {
  it('should do things', function() {
    const foo = 'bar';

    expect(foo).to.be.a('string');
    expect(foo).to.equal('bar');
    expect(foo).to.have.lengthOf(3);
    expect(foo).not.to.be.null;
  });
});
/* expect available globally */

describe('foo', () => {
  it('should do things', () => {
    const foo = 'bar';

    expect(typeof foo).toBe('string');
    expect(foo).toEqual('bar');
    expect(foo).toHaveLength(3);
    expect(foo).not.toBeNull();
  });
});

Infinite Jest: Unit Testing With Jest

By unicode

Infinite Jest: Unit Testing With Jest

https://github.com/GWShark0/jest-walkthrough

  • 149