unexpected-react icon indicating copy to clipboard operation
unexpected-react copied to clipboard

Are assertions on fragments supported? (ReactTestRenderer)

Open lukehorvat opened this issue 4 years ago • 0 comments

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?

lukehorvat avatar Jun 12 '20 17:06 lukehorvat