Skip to content

Support testing for a component to render nothing #16

@albertfdp

Description

@albertfdp
it('renders nothing', () => {
  const RenderNull = React.createClass({
    render: () => null
  })

  expect(<RenderNull/>, 'to have rendered', null)
})

The error message you get:

expected <RenderNull /> to have rendered null
      No matching assertion, did you mean:
      <ReactElement> to have [exactly] rendered <ReactElement>
      <ReactElement> to have rendered [with all children] [with all wrappers] <ReactElement>
      <ReactShallowRenderer> to have [exactly] rendered <ReactElement>
      <ReactShallowRenderer> to have rendered [with all children] [with all wrappers] <ReactElement>
      <RenderedReactElement> to have [exactly] rendered <ReactElement>
      <RenderedReactElement> to have rendered [with all children] [with all wrappers] <ReactElement>

It would be nice to support the following:

expect(<RenderNull />, 'to have rendered', null)

and

expect(<RenderNull />, 'to have rendered nothing')

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions