Skip to content
This repository has been archived by the owner on Aug 1, 2018. It is now read-only.

Commit

Permalink
Support React.Fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinGrandon authored and fusion-bot[bot] committed Mar 26, 2018
1 parent fda3fb2 commit 96a8d29
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 47 additions & 0 deletions src/__tests__/__node__/prepare-render.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,50 @@ tape('Preparing an async app with componentWillReceiveProps option', t => {
t.end();
});
});

tape('Preparing a Fragment', t => {
const app = (
<React.Fragment>
<span>1</span>
<span>2</span>
</React.Fragment>
);
const p = prepare(app);
t.ok(p instanceof Promise, 'prepare returns a promise');
p.then(() => {
const wrapper = shallow(<div>{app}</div>);
t.equal(wrapper.find('span').length, 2, 'has two children');
t.end();
});
});

tape('Preparing a fragment with async children', t => {
let numChildRenders = 0;
let numPrepares = 0;
function SimplePresentational() {
numChildRenders++;
return <div>Hello World</div>;
}
const AsyncChild = prepared(props => {
numPrepares++;
t.equal(
props.data,
'test',
'passes props through to prepared component correctly'
);
return Promise.resolve();
})(SimplePresentational);
const app = (
<React.Fragment>
<AsyncChild data="test" />
<AsyncChild data="test" />
</React.Fragment>
);
const p = prepare(app);
t.ok(p instanceof Promise, 'prepare returns a promise');
p.then(() => {
t.equal(numPrepares, 2, 'runs prepare function twice');
t.equal(numChildRenders, 2, 'renders SimplePresentational twice');
t.end();
});
});
2 changes: 1 addition & 1 deletion src/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function prepareElement(element, context) {
return Promise.resolve([null, context]);
}
const {type, props} = element;
if (typeof type === 'string') {
if (typeof type === 'string' || type === React.Fragment) {
return Promise.resolve([props.children, context]);
}
if (!isReactCompositeComponent(type)) {
Expand Down

0 comments on commit 96a8d29

Please sign in to comment.