Fix bug in cloneWithProps()
Pete Hunt committed
Jan 6, 2014 at 18:20 UTC
1e980a146f2e500c4beaac2240b0a072eedb70d5
2 files changed
+29
-1
src/core/ReactCompositeComponent.js
+1
@@ -1231,6 +1231,7 @@ var ReactCompositeComponent = {
1231
return instance;
1232
};
1233
ConvenienceConstructor.componentConstructor = Constructor;
1234
+ Constructor.ConvenienceConstructor = ConvenienceConstructor;
1235
ConvenienceConstructor.originalSpec = spec;
1236
1237
mixSpecIntoComponent(ConvenienceConstructor, spec);
src/utils/__tests__/cloneWithProps-test.js
+28
-1
@@ -38,7 +38,7 @@ describe('cloneWithProps', function() {
38
onlyChild = require('onlyChild');
39
});
40
41
- it('should clone an object with new props', function() {
41
+ it('should clone a DOM component with new props', function() {
42
var Grandparent = React.createClass({
43
render: function() {
44
return <Parent><div className="child" /></Parent>;
@@ -58,6 +58,33 @@ describe('cloneWithProps', function() {
58
.toBe('child xyz');
59
});
60
61
+ it('should clone a composite component with new props', function() {
62
+
63
+ var Child = React.createClass({
64
+ render: function() {
65
+ return <div className={this.props.className} />;
66
+ }
67
+ });
68
+
69
+ var Grandparent = React.createClass({
70
+ render: function() {
71
+ return <Parent><Child className="child" /></Parent>;
72
+ }
73
+ });
74
+ var Parent = React.createClass({
75
+ render: function() {
76
+ return (
77
+ <div className="parent">
78
+ {cloneWithProps(onlyChild(this.props.children), {className: 'xyz'})}
79
+ </div>
80
+ );
81
+ }
82
+ });
83
+ var component = ReactTestUtils.renderIntoDocument(<Grandparent />);
84
+ expect(component.getDOMNode().childNodes[0].className)
85
+ .toBe('child xyz');
86
+ });
87
+
88
it('should warn when cloning with refs', function() {
89
var Grandparent = React.createClass({
90
render: function() {