Skip to content

Latest commit

 

History

History
58 lines (42 loc) · 1.24 KB

installation-jest.md

File metadata and controls

58 lines (42 loc) · 1.24 KB

Set up with Jest in Create React App

This guide will use specific versions NPM packages. Please double-check that you installed the same versions to avoid installation issues!

  1. Install Create React App
$ npm install -g [email protected]
  1. Create a new React application
$ create-react-app my-app
$ cd my-app
  1. Install react-page-object, enzyme, and react-test-renderer
$ npm i -D react-page-object [email protected] [email protected]
  1. Modify the contents of src/App.test.js to be:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import Page from 'react-page-object';

it('renders without crashing', () => {
  const div = document.createElement('div');
  ReactDOM.render(<App />, div);
});

describe('Passing test', () => {
  let page;

  beforeEach(() => {
    page = new Page(<App />)
  });

  afterEach(() => {
    page.destroy();
  });

  it('should pass', () => {
    expect(page.content()).toMatch(/Welcome to React/)
  });
})

At this point, the set up is complete! You can run Jest as before with:

$ npm test