Add test for warning in ReactElementValidator
I previously had a mistake here, so I'm adding a unit test to ensure that I don't make the same mistake again.
Sebastian Markbage committed
Nov 16, 2014 at 16:59 UTC
63644d5e71356d422603c0faef6b664c1bdb1f42
2 files changed
+31
-1
src/core/ReactElementValidator.js
+1
-1
@@ -160,7 +160,7 @@ function monitorUseOfObjectMap() {
160
}
161
162
/**
163
- * Ensure that every component either is passed in a static location, in an
163
+ * Ensure that every element either is passed in a static location, in an
164
* array with an explicit keys property defined, or in an object literal
165
* with valid key property.
166
*
src/core/__tests__/ReactElement-test.js
+30
@@ -173,6 +173,36 @@ describe('ReactElement', function() {
173
);
174
});
175
176
+ it('warns for keys for arrays of elements in rest args', function() {
177
+ spyOn(console, 'warn');
178
+ var Component = React.createFactory(ComponentClass);
179
+
180
+ var InnerClass = React.createClass({
181
+ displayName: 'InnerClass',
182
+ render: function() {
183
+ return Component(null, this.props.childSet);
184
+ }
185
+ });
186
+
187
+ var InnerComponent = React.createFactory(InnerClass);
188
+
189
+ var ComponentWrapper = React.createClass({
190
+ displayName: 'ComponentWrapper',
191
+ render: function() {
192
+ return InnerComponent({ childSet: [ Component(), Component() ] });
193
+ }
194
+ });
195
+
196
+ ReactTestUtils.renderIntoDocument(<ComponentWrapper />);
197
+
198
+ expect(console.warn.argsForCall.length).toBe(1);
199
+ expect(console.warn.argsForCall[0][0]).toContain(
200
+ 'Each child in an array or iterator should have a unique "key" prop. ' +
201
+ 'Check the render method of InnerClass. ' +
202
+ 'It was passed a child from ComponentWrapper. '
203
+ );
204
+ });
205
+
206
it('warns for keys for iterables of elements in rest args', function() {
207
spyOn(console, 'warn');
208
var Component = React.createFactory(ComponentClass);