Don't transfer children in transferPropsTo

06cff60bc1 made it so that `this.props.children` was no longer set when
none were provided.

  var x = <div />;

This caused an issue if the code was relying on the following not
transferring children.

  return this.transferPropsTo(<div />);
  // this now transfer children
This commit is contained in:
CommitSyncScript
2013-06-18 09:32:23 -07:00
committed by Paul O’Shannessy
parent 5bd449c157
commit 37ddfa0521
2 changed files with 28 additions and 5 deletions
+6 -2
View File
@@ -44,13 +44,17 @@ function createTransferStrategy(mergeStrategy) {
*/
var TransferStrategies = {
/**
* Never transfer the `ref` prop.
* Never transfer `children`.
*/
ref: emptyFunction,
children: emptyFunction,
/**
* Transfer the `className` prop by merging them.
*/
className: createTransferStrategy(joinClasses),
/**
* Never transfer the `ref` prop.
*/
ref: emptyFunction,
/**
* Transfer the `style` prop (which is an object) by merging them.
*/
@@ -51,7 +51,7 @@ describe('ReactCompositeComponent-transferProps', function() {
ReactTestUtils.renderIntoDocument(instance);
reactComponentExpect(instance)
.expectRenderedChild(instance)
.expectRenderedChild()
.toBeDOMComponentWithTag('input')
.scalarPropsEqual({
className: 'textinput',
@@ -66,7 +66,7 @@ describe('ReactCompositeComponent-transferProps', function() {
ReactTestUtils.renderIntoDocument(instance);
reactComponentExpect(instance)
.expectRenderedChild(instance)
.expectRenderedChild()
.toBeDOMComponentWithTag('input')
.scalarPropsEqual({placeholder: 'Type here...'});
});
@@ -80,7 +80,7 @@ describe('ReactCompositeComponent-transferProps', function() {
ReactTestUtils.renderIntoDocument(instance);
reactComponentExpect(instance)
.expectRenderedChild(instance)
.expectRenderedChild()
.toBeDOMComponentWithTag('input')
.scalarPropsEqual({
className: 'textinput hidden_elem',
@@ -91,6 +91,25 @@ describe('ReactCompositeComponent-transferProps', function() {
});
});
it('should not transfer children', function() {
var ChildrenTestComponent = React.createClass({
render: function() {
return this.transferPropsTo(<div />);
}
});
var instance =
<ChildrenTestComponent>
<span>Hello!</span>
</ChildrenTestComponent>;
ReactTestUtils.renderIntoDocument(instance);
reactComponentExpect(instance)
.expectRenderedChild()
.toBeDOMComponentWithTag('div')
.toBeDOMComponentWithNoChildren();
});
it('should not transfer ref', function() {
var RefTestComponent = React.createClass({
render: function() {