Home > Blockchain >  How to pass React component as regular JS to react-test-renderer
How to pass React component as regular JS to react-test-renderer

Time:11-26

I see only examples with components in JSX.

But how to pass a component as regular JS React.createElement() instead of JSX something like

const testRenderer = ReactTestRenderer.create(
    React.createElement('div', null, 'Text');
);

Now with this code I get the error

missing ) after argument list

ps. React on Node.js

CodePudding user response:

This is how you would do it. (Meaning almost like you did it) (https://reactjs.org/docs/react-api.html#createelement) But you have an extra semicolon inside the create argument list.

const testRenderer = ReactTestRenderer.create(
    React.createElement('div', null, 'Text')
);

  • Related