Skip to content

Are assertions on fragments supported? (ReactTestRenderer) #59

Description

@lukehorvat

Hi. I tried the following assertion:

class TextComponent extends React.Component {
  render() {
    return <React.Fragment>{this.props.text}</React.Fragment>;
  }
}

const comp = ReactTestRenderer.create(<TextComponent text={'foo'} />);
expect(comp, 'to have rendered', <React.Fragment>foo</React.Fragment>);

But it fails with an error:

expected foo to have rendered <no-display-name>foo</no-display-name>

foo // should be <no-display-name>foo</no-display-name>

So I tried this assertion instead:

expect(comp, 'to have rendered', 'foo');

But that gives another error:

expected foo to have rendered 'foo'
  The assertion does not have a matching signature for:
    <ReactTestRenderer> to have rendered <string>
  did you mean:
    <ReactTestRenderer> to have [exactly] rendered <ReactElement>
    <ReactTestRenderer> to have rendered [with all children] [with all wrappers] [with all classes] [with all attributes] <ReactElement>
    <ReactTestRendererOutput> to have [exactly] rendered <ReactElement>
    <ReactTestRendererOutput> to have rendered [with all children] [with all wrappers] [with all classes] [with all attributes] <ReactElement>
    <ReactTestRendererPendingEvent> to have [exactly] rendered [with all children] [with all wrappers] [with all classes] [with all attributes] <ReactElement>

Am I doing something wrong? Is this the same issue being discussed in #52?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions