enzyme
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
array.prototype.flat | 1.3.2 | 6.64 kB | MIT | prod | |
cheerio | 1.0.0-rc.12 | 75.06 kB | MIT | prod | |
enzyme-shallow-equal | 1.0.7 | 11.2 kB | MIT | prod | |
function.prototype.name | 1.1.6 | 8.67 kB | MIT | prod | |
has | 1.0.4 | 1.59 kB | MIT | prod | |
html-element-map | 1.3.1 | 8.83 kB | MIT | prod | |
is-boolean-object | 1.1.2 | 7.67 kB | MIT | prod | |
is-callable | 1.2.7 | 9.66 kB | MIT | prod | |
is-number-object | 1.0.7 | 7.7 kB | MIT | prod | |
is-regex | 1.1.4 | 10.31 kB | MIT | prod | |
is-string | 1.0.7 | 6.92 kB | MIT | prod | |
is-subset | 0.1.1 | 3.45 kB | MIT | prod | |
lodash.escape | 4.0.1 | 3.79 kB | MIT | prod | |
lodash.isequal | 4.5.0 | 12.02 kB | MIT | prod | |
object-inspect | 1.13.1 | 25.91 kB | MIT | prod | |
object-is | 1.1.6 | 26.39 kB | MIT | prod | |
object.assign | 4.1.5 | 18.68 kB | MIT | prod | |
object.entries | 1.1.8 | 31.8 kB | MIT | prod | |
object.values | 1.2.0 | 30.78 kB | MIT | prod | |
raf | 3.4.1 | 3.63 kB | MIT | prod | |
rst-selector-parser | 2.2.3 | 65 kB | BSD-3-Clause | prod | 1 |
string.prototype.trim | 1.2.9 | 32.74 kB | MIT | prod |
Enzyme is a JavaScript testing utility for React that simplifies the testing of React components' output displays and behaviors. It allows developers to manipulate, traverse, and in some ways simulate runtime interactions with their component's output.
Using Enzyme involves a straightforward and intuitive process, in a manner similar to that of working with jQuery's API for DOM manipulation and traversal. Prior to using Enzyme, you need to install it via npm alongside an Adapter corresponding to your version of React, by running a command such as npm i --save-dev enzyme enzyme-adapter-react-16
for React 16.
After installation, import Enzyme and your chosen Adapter into your test files, then configure Enzyme to use the adapter as follows:
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({ adapter: new Adapter() });
To write tests using Enzyme's shallow rendering API for instance, the following code example demonstrates how to test various aspects of your React component:
import React from 'react';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import MyComponent from './MyComponent';
describe('<MyComponent />', () => {
const wrapper = shallow(<MyComponent />);
it('renders three <Foo /> components', () => {
expect(wrapper.find(Foo)).to.have.lengthOf(3);
});
//...more tests
})
Enzyme's documentation and additional guidelines can be found inside its GitHub repository at the URL 'https://github.com/airbnb/enzyme'. The documentation covers a wide range of topics, explaining the basic usage of Enzyme, its APIs, setup guides with different testing frameworks, React Hooks support, and more. Detailed API documentation can be found in '/docs/api/', and general guides can be found in '/docs/guides/'. The updated documentation is designed to provide comprehensive information and knowledge that a developer would typically need to use Enzyme effectively.