Skip to content
Branch: master
Find file Copy path
Find file Copy path
53 lines (42 sloc) 1.78 KB

Static Rendering API

Use enzyme's render function to generate HTML from your React tree, 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. You can reference the Cheerio API docs for methods available on a CheerioWrapper instance.

Example Usage

import React from 'react';
import { render } from 'enzyme';
import PropTypes from 'prop-types';

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

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

  it('renders a div', () => {
    const wrapper = render(<div className="myClass" />);

  it('can pass in context', () => {
    function SimpleComponent(props, context) {
      const { name } = context;
      return <div>{name}</div>;
    SimpleComponent.contextTypes = {
      name: PropTypes.string,

    const context = { name: 'foo' };
    const wrapper = render(<SimpleComponent />, { context });
You can’t perform that action at this time.