简体   繁体   中英

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

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

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')
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM