Testing React components
Just like with utility modules, creating tests for React components starts with creating the __tests__
directory. Navigate to ~/snapterest/source/components/
and create the __tests__
directory.
The first React component that we'll test will be our Header
component. Create Header-test.js
in the ~/snapterest/source/components/__tests__
directory:
jest.dontMock('../Header.react'); describe('Header component', function () { it('renders provided header text', function () { var React = require('react'); var ReactDOM = require('react-dom'); var TestUtils = require('react-addons-test-utils'); var Header = require('../Header.react'); var header = TestUtils.renderIntoDocument( <Header text="Testing..." /> ); var actualHeaderText = ReactDOM.findDOMNode(header).textContent; expect(actualHeaderText).toBe('Testing...'); var defaultHeader = TestUtils.renderIntoDocument( <Header /> ); var actualDefaultHeaderText...