Skip to content

Commit

Permalink
Added more comprehensive tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Poole committed Jul 5, 2016
1 parent 2f3e941 commit 0a256c4
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions tests/multiple.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,20 @@ const TodoList = React.createClass({
this.setState({ items: newItems });
},

insertUndefined(i) {
const newItems = this.state.items;
newItems.splice(i, 1, undefined);
this.setState({ items: newItems });
},

render() {
const items = this.state.items.map((item, i) => {
// Allow testing of null/undefined values by just passing them directly to
// Animate instead of wrapping them with a Todo component
if (item === null || item === undefined) {
return item;
}

return (
<Todo key={item} onClick={this.handleRemove.bind(this, i)}>
{item}
Expand Down Expand Up @@ -139,15 +151,30 @@ describe('Animate', () => {
}, 1400);
});

it('does not fail with null/undefined children', (done) => {
ReactDOM.render(
<Animate>
{undefined}
{null}
<div key="test"></div>
</Animate>,
container,
done
);
it('does not generate an error when a null or undefined child is present', () => {
list.handleAdd(null);
expect(TestUtils.scryRenderedDOMComponentsWithClass(list, 'item').length).to.be(4);
list.handleAdd(undefined);
expect(TestUtils.scryRenderedDOMComponentsWithClass(list, 'item').length).to.be(4);
});

it('transitionLeave works when a child becomes undefined', function t4(done) {
this.timeout(5999);
list.insertUndefined(0);
setTimeout(() => {
expect(TestUtils.scryRenderedDOMComponentsWithClass(list, 'item').length).to.be(4);
if (!window.callPhantom) {
expect(TestUtils.scryRenderedDOMComponentsWithClass(list, 'item')[0].className)
.to.contain('example-leave');
expect(TestUtils.scryRenderedDOMComponentsWithClass(list, 'item')[0].className)
.to.contain('example-leave-active');
}
}, 100);
setTimeout(() => {
if (!window.callPhantom) {
expect(TestUtils.scryRenderedDOMComponentsWithClass(list, 'item').length).to.be(3);
}
done();
}, 1400);
});
});

0 comments on commit 0a256c4

Please sign in to comment.