80
.toEqual('.reactRoot[0].:2.:chipmunk');
81
});
82
83
+ it('should let restructured components retain their uniqueness', function() {
84
+ var instance0 = <span />;
85
+ var instance1 = <span />;
86
+ var instance2 = <span />;
87
+ var wrapped = <div>{instance0} {instance1}</div>;
88
+ var unwrappedAndAdded =
89
+ <div>
90
+ {instance2}
91
+ {wrapped.props.children[0]}
92
+ {wrapped.props.children[1]}
93
+ </div>;
94
+
95
+ expect(function() {
96
+
97
+ React.renderComponent(unwrappedAndAdded, document.createElement('div'));
98
+
99
+ }).not.toThrow();
100
+ });
101
+
102
+ it('should retain keys during updates in composite components', function() {
103
+
104
+ var TestComponent = React.createClass({
105
+ render: function() {
106
+ return <div>{this.props.children}</div>;
107
+ }
108
+ });
109
+
110
+ var TestContainer = React.createClass({
111
+
112
+ getInitialState: function() {
113
+ return { swapped: false };
114
+ },
115
+
116
+ swap: function() {
117
+ this.setState({ swapped: true });
118
+ },
119
+
120
+ render: function() {
121
+ return (
122
+ <TestComponent>
123
+ {this.state.swapped ? this.props.second : this.props.first}
124
+ {this.state.swapped ? this.props.first : this.props.second}
125
+ </TestComponent>
126
+ );
127
+ }
128
+
129
+ });
130
+
131
+ var instance0 = <span key="A" />;
132
+ var instance1 = <span key="B" />;
133
+
134
+ var wrapped = <TestContainer first={instance0} second={instance1} />;
135
+
136
+ React.renderComponent(wrapped, document.createElement('div'));
137
+
138
+ var beforeKey = wrapped
139
+ ._renderedComponent
140
+ ._renderedComponent
141
+ .props.children[0]._key;
142
+
143
+ wrapped.swap();
144
+
145
+ var afterKey = wrapped
146
+ ._renderedComponent
147
+ ._renderedComponent
148
+ .props.children[0]._key;
149
+
150
+ expect(beforeKey).not.toEqual(afterKey);
151
+
152
+ });
153
+
154
});