enzyme's render function is used to render react components to static HTML and analyze the
resulting HTML structure.
render returns a wrapper very similar to the other renderers in enzyme, mount and
shallow; however, render uses a third party HTML parsing and traversal library
Cheerio. We believe that Cheerio handles parsing and
traversing HTML extremely well, and duplicating this functionality ourselves would be a
disservice.
For the purposes of this documentation, we will refer to Cheerio's constructor as
CheerioWrapper, which is to say that it is analogous to our ReactWrapper and ShallowWrapper
constructors.
importReactfrom'react';import{render}from'enzyme';importPropTypesfrom'prop-types';describe('<Foo />',()=>{it('renders three `.foo-bar`s',()=>{constwrapper=render(<Foo/>);expect(wrapper.find('.foo-bar')).to.have.length(3);});it('rendered the title',()=>{constwrapper=render(<Footitle="unique"/>);expect(wrapper.text()).to.contain('unique');});it('can pass in context',()=>{functionSimpleComponent(props,context){const{ name }=context;return<div>{name}</div>;}SimpleComponent.contextTypes={name: PropTypes.string,};constcontext={name: 'foo'};constwrapper=render(<SimpleComponent/>,{ context });expect(wrapper.text()).to.equal('foo');});});