React 16 fragments (rendering arrays and strings) unsupported
See original GitHub issueReact 16 added a new return type of an array with many fragments of JSX, see React 16 blog post
Enzyme v3.0.0 with React 16 adapter 1.0.0 throws an error with this sample code
Error
/node_modules/react-dom/cjs/react-dom-server.node.development.js:2776
var tag = element.type.toLowerCase();
^
TypeError: Cannot read property 'toLowerCase' of undefined
Failing test
import Adapter from 'enzyme-adapter-react-16';
import { configure, shallow } from 'enzyme';
import React from 'react';
import test from 'tape';
function Fragments() {
return [
<li key="A">First item</li>,
<li key="B" id="item">Second item</li>,
<li key="C">Third item</li>
];
}
test('One element parent', (assert) => {
configure({ adapter: new Adapter() });
const wrapper = shallow(<Fragments />);
const actual = wrapper.html();
const expected = undefined;
assert.notEqual(actual, expected, 'Has ID selector');
assert.end();
});
Passing test
import Adapter from 'enzyme-adapter-react-16';
import { configure, shallow } from 'enzyme';
import React from 'react';
import test from 'tape';
function NotFragments() {
return (
<ul>
<li key="A">First item</li>,
<li key="B" id="item">Second item</li>,
<li key="C">Third item</li>
</ul>
);
}
test('One element parent', (assert) => {
configure({ adapter: new Adapter() });
const wrapper = shallow(<NotFragments />);
const actual = wrapper.find('#item').is('li');
const expected = true;
assert.equal(actual, expected, 'Has ID selector');
assert.end();
});
-=Dan=-
Issue Analytics
- State:
- Created 6 years ago
- Reactions:55
- Comments:32 (8 by maintainers)
Top Results From Across the Web
React v16.2.0: Improved Support for Fragments
React 16.2 is now available! The biggest addition is improved support for returning multiple children from a component's render method.
Read more >Using React 16 Fragments for the First Time | by John Wolfe
React 16 ushered in a flurry of new tools for React developers, including portals, ... and fragments, strings, and arrays instead of divs....
Read more >Rendering React Components from Array of Objects
You can map the list of stations to ReactElements. With React >= 16, it is possible to return multiple elements from the same...
Read more >Getting started with React 16 | Arun Michael Dsouza
Fragments and Strings. React 16 gives you the ability to return elements in an array from the render method. That means, for the...
Read more >Render Children in React Using Fragment or Array Components
What comes to your mind when React 16 comes up? Context? Error Boundary? Those are on point. React 16 came with those goodies...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Temporary hack that seems to work well enough:
Best solution I’ve found so far: wrap fragments with
<div>
for the tests only.