ReactTransitionGroup: Fix changing to null child

Fixes #1457.

Test Plan: grunt fasttest
This commit is contained in:
Ben Alpert
2014-04-28 20:52:42 -03:00
parent d657479a9d
commit 9dbbaf12bf
2 changed files with 25 additions and 4 deletions
@@ -61,15 +61,15 @@ var ReactTransitionGroup = React.createClass({
var key;
for (key in nextChildMapping) {
if (!prevChildMapping.hasOwnProperty(key) &&
!this.currentlyTransitioningKeys[key]) {
var hasPrev = prevChildMapping && prevChildMapping.hasOwnProperty(key);
if (!hasPrev && !this.currentlyTransitioningKeys[key]) {
this.keysToEnter.push(key);
}
}
for (key in prevChildMapping) {
if (!nextChildMapping.hasOwnProperty(key) &&
!this.currentlyTransitioningKeys[key]) {
var hasNext = nextChildMapping && nextChildMapping.hasOwnProperty(key);
if (!hasNext && !this.currentlyTransitioningKeys[key]) {
this.keysToLeave.push(key);
}
}
@@ -142,4 +142,25 @@ describe('ReactCSSTransitionGroup', function() {
container
);
});
it('should transition from one to null', function() {
var a = React.renderComponent(
<ReactCSSTransitionGroup transitionName="yolo">
<span key="one" id="one" />
</ReactCSSTransitionGroup>,
container
);
expect(a.getDOMNode().childNodes.length).toBe(1);
React.renderComponent(
<ReactCSSTransitionGroup transitionName="yolo">
{null}
</ReactCSSTransitionGroup>,
container
);
// (Here, we expect the original child to stick around but test that no
// exception is thrown)
expect(a.getDOMNode().childNodes.length).toBe(1);
expect(a.getDOMNode().childNodes[0].id).toBe('one');
});
});