Enzyme

Enzyme is a library designed to aid in the testing of React components.

To install Enzyme into your project, execute the following command:

>npm install enzyme react-test-renderer react-dom

The extra libraries listed, react-test-renderer and react-domare dependencies of Enzyme that it needs to function correctly.

As with the other testing utilities mentioned in this section, we will get into usage as needed, while we discuss the topics covered in this book. But here is a quick example of a test using Enzyme from the Enzyme documentation at https://github.com/airbnb/enzyme:

import React from 'react';
import { expect } from 'chai';
import { render } from 'enzyme';
import Foo from './Foo';

describe('<Foo />', () => {
it('renders three `.foo-bar`s', () => {
const wrapper = render(<Foo />);

expect(wrapper.find('.foo-bar').length).to.equal(3);
});

it('renders the title', () => {
const wrapper = render(<Foo title="unique" />);

expect(wrapper.text()).to.contain('unique');
});});
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.72.15