Skip to content

Commit

Permalink
Add test for react16 fragment support
Browse files Browse the repository at this point in the history
  • Loading branch information
tobilen committed Oct 1, 2017
1 parent ee2f614 commit 9022b85
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ describe('FlipMove', () => {
}
};

class ListItemsFragment extends Component {
render() {
return articles.map(article => (
<ListItem
key={article ? article.id : null}
id={article ? article.id : null}
name={article ? article.name : null}
/>
));
}
}

// We need our list parent, which contains our FlipMove as well as
// all the list items.
const ListParent = class ListParent extends Component {
Expand All @@ -58,6 +70,7 @@ describe('FlipMove', () => {
disableAllAnimations: this.props.disableAllAnimations || false,
maintainContainerHeight: this.props.maintainContainerHeight || false,
articles: this.props.articles || articles,
useFragment: this.props.useFragment || false,
};

count = 0;
Expand All @@ -71,13 +84,17 @@ describe('FlipMove', () => {
};

renderArticles() {
return this.state.articles.map(article => (
<ListItem
key={article ? article.id : null}
id={article ? article.id : null}
name={article ? article.name : null}
/>
));
return this.state.useFragment ? (
<ListItemsFragment articles={this.state.articles} />
) : (
this.state.articles.map(article => (
<ListItem
key={article ? article.id : null}
id={article ? article.id : null}
name={article ? article.name : null}
/>
))
);
}

render() {
Expand Down Expand Up @@ -129,6 +146,20 @@ describe('FlipMove', () => {
expect(outputComponents.at(2).prop('id')).to.equal('c');
});

it('renders the children components as fragments', () => {
const wrapper = mount(<ListParent useFragment />);

expect(wrapper.find(ListItem).length).to.equal(3);
expect(wrapper.find('li').length).to.equal(3);

const outputComponents = wrapper.find(ListItem);

// Check that they're rendered in order
expect(outputComponents.at(0).prop('id')).to.equal('a');
expect(outputComponents.at(1).prop('id')).to.equal('b');
expect(outputComponents.at(2).prop('id')).to.equal('c');
});

describe('updating state', () => {
let originalPositions;

Expand Down

0 comments on commit 9022b85

Please sign in to comment.