Remove warnings in tests
For #3890. Squashed merge, closes #3925.
li.li committed
May 20, 2015 at 16:48 UTC
63d04715807084bf5169c9e815f4c3fdcb8b53b7
10 files changed
+54
-18
src/isomorphic/children/__tests__/ReactChildren-test.js
+2
-1
@@ -75,7 +75,7 @@ describe('ReactChildren', function() {
75
return kid;
76
});
77
78
- var simpleKid = <span />;
78
+ var simpleKid = <span key="simple" />;
79
var instance = <div>{[simpleKid]}</div>;
80
ReactChildren.forEach(instance.props.children, callback);
81
expect(callback).toHaveBeenCalledWith(simpleKid, 0);
@@ -83,6 +83,7 @@ describe('ReactChildren', function() {
83
var mappedChildren = ReactChildren.map(instance.props.children, callback);
84
expect(callback).toHaveBeenCalledWith(simpleKid, 0);
85
expect(nthChild(mappedChildren, 0)).toBe(simpleKid);
86
+
87
});
88
89
it('should pass key to returned component', function() {
src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee
+3
@@ -44,10 +44,13 @@ describe 'ReactCoffeeScriptClass', ->
44
expect(Foo.name).toBe 'Foo'
45
46
it 'throws if no render function is defined', ->
47
+ spyOn console, 'error'
48
class Foo extends React.Component
49
expect(->
50
React.render React.createElement(Foo), container
51
).toThrow()
52
+ expect(console.error.calls.length).toBe(1)
53
+ expect(console.error.calls[0].args[0]).toContain('No `render` method found on the returned component instance')
54
55
it 'renders a simple stateless component with prop', ->
56
class Foo
src/isomorphic/modern/class/__tests__/ReactES6Class-test.js
+2
@@ -58,6 +58,8 @@ describe('ReactES6Class', function() {
58
spyOn(console, 'error');
59
class Foo extends React.Component { }
60
expect(() => React.render(<Foo />, container)).toThrow();
61
+
62
+ expect(console.error.calls.length).toBe(1);
63
expect(console.error.calls[0].args[0]).toBe(
64
'Warning: Foo(...): ' +
65
'No `render` method found on the returned component instance: you may ' +
src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts
+12
@@ -311,7 +311,19 @@ describe('ReactTypeScriptClass', function() {
311
});
312
313
it('throws if no render function is defined', function() {
314
+ var warn = jest.genMockFn();
315
+ console.error = warn;
316
+
317
expect(() => React.render(React.createElement(Empty), container)).toThrow();
318
+
319
+ expect(warn.mock.calls.length).toBe(1);
320
+ expect(warn.mock.calls[0][0]).toBe(
321
+ 'Warning: Empty(...): ' +
322
+ 'No `render` method found on the returned component instance: you may ' +
323
+ 'have forgotten to define `render` in your component or you may have ' +
324
+ 'accidentally tried to render an element whose type is a function that ' +
325
+ 'isn\'t a React component.'
326
+ );
327
});
328
329
it('renders a simple stateless component with prop', function() {
src/renderers/dom/client/ReactMount.js
+2
-1
@@ -525,7 +525,8 @@ var ReactMount = {
525
);
526
527
warning(
528
- container && container.tagName && container.tagName.toUpperCase() !== 'BODY',
528
+ !container || !container.tagName ||
529
+ container.tagName.toUpperCase() !== 'BODY',
530
'render(): Rendering components directly into document.body is ' +
531
'discouraged, since its children are often manipulated by third-party ' +
532
'scripts and browser extensions. This may lead to subtle ' +
src/renderers/dom/client/eventPlugins/__tests__/EnterLeaveEventPlugin-test.js
+2
-2
@@ -37,11 +37,11 @@ describe('EnterLeaveEventPlugin', function() {
37
var iframeDocument = iframe.contentDocument;
38
39
iframeDocument.write(
40
- '<!DOCTYPE html><html><head></head><body></body></html>'
40
+ '<!DOCTYPE html><html><head></head><body><div></div></body></html>'
41
);
42
iframeDocument.close();
43
44
- var component = React.render(<div />, iframeDocument.body);
44
+ var component = React.render(<div />, iframeDocument.body.getElementsByTagName('div')[0]);
45
var div = React.findDOMNode(component);
46
47
var extracted = EnterLeaveEventPlugin.extractEvents(
src/renderers/dom/client/wrappers/__tests__/ReactDOMOption-test.js
+3
@@ -30,11 +30,14 @@ describe('ReactDOMOption', function() {
30
});
31
32
it('should ignore invalid children types', function() {
33
+ spyOn(console, 'error');
34
var stub = <option>{1} <div /> {2}</option>;
35
stub = ReactTestUtils.renderIntoDocument(stub);
36
var node = React.findDOMNode(stub);
37
38
expect(node.innerHTML).toBe('1 2');
39
+ expect(console.error.calls.length).toBe(1);
40
+ expect(console.error.calls[0].args[0]).toContain('Only strings and numbers are supported as <option> children.');
41
});
42
43
it('should warn when passing invalid children', function() {
src/renderers/dom/client/wrappers/__tests__/ReactDOMSelect-test.js
+21
-14
@@ -19,6 +19,8 @@ describe('ReactDOMSelect', function() {
19
var ReactLink;
20
var ReactTestUtils;
21
22
+ var noop = function() {};
23
+
24
beforeEach(function() {
25
React = require('React');
26
ReactLink = require('ReactLink');
@@ -103,7 +105,7 @@ describe('ReactDOMSelect', function() {
105
106
it('should allow setting `value`', function() {
107
var stub =
106
- <select value="giraffe">
108
+ <select value="giraffe" onChange={noop}>
109
<option value="monkey">A monkey!</option>
110
<option value="giraffe">A giraffe!</option>
111
<option value="gorilla">A gorilla!</option>
@@ -117,14 +119,14 @@ describe('ReactDOMSelect', function() {
119
120
// Changing the `value` prop should change the selected option.
121
React.render(
120
- <select value="gorilla">{options}</select>,
122
+ <select value="gorilla" onChange={noop}>{options}</select>,
123
container
124
);
125
expect(node.value).toEqual('gorilla');
126
});
127
128
it('should not throw with `value` and without children', function() {
127
- var stub = <select value="dummy"></select>;
129
+ var stub = <select value="dummy" onChange={noop}></select>;
130
131
expect(() => {
132
ReactTestUtils.renderIntoDocument(stub);
@@ -133,7 +135,7 @@ describe('ReactDOMSelect', function() {
135
136
it('should allow setting `value` with multiple', function() {
137
var stub =
136
- <select multiple={true} value={['giraffe', 'gorilla']}>
138
+ <select multiple={true} value={['giraffe', 'gorilla']} onChange={noop}>
139
<option value="monkey">A monkey!</option>
140
<option value="giraffe">A giraffe!</option>
141
<option value="gorilla">A gorilla!</option>
@@ -149,7 +151,9 @@ describe('ReactDOMSelect', function() {
151
152
// Changing the `value` prop should change the selected options.
153
React.render(
152
- <select multiple={true} value={['monkey']}>{options}</select>,
154
+ <select multiple={true} value={['monkey']} onChange={noop}>
155
+ {options}
156
+ </select>,
157
container
158
);
159
@@ -160,7 +164,7 @@ describe('ReactDOMSelect', function() {
164
165
it('should not select other options automatically', function() {
166
var stub =
163
- <select multiple={true} value={['12']}>
167
+ <select multiple={true} value={['12']} onChange={noop}>
168
<option value="1">one</option>
169
<option value="2">two</option>
170
<option value="12">twelve</option>
@@ -174,12 +178,12 @@ describe('ReactDOMSelect', function() {
178
});
179
180
it('should reset child options selected when they are changed and `value` is set', function() {
177
- var stub = <select multiple={true} value={['a', 'b']} />;
181
+ var stub = <select multiple={true} value={['a', 'b']} onChange={noop} />;
182
var container = document.createElement('div');
183
stub = React.render(stub, container);
184
185
React.render(
182
- <select multiple={true} value={['a', 'b']}>
186
+ <select multiple={true} value={['a', 'b']} onChange={noop}>
187
<option value="a">a</option>
188
<option value="b">b</option>
189
<option value="c">c</option>
@@ -203,7 +207,7 @@ describe('ReactDOMSelect', function() {
207
};
208
209
var el =
206
- <select multiple={true} value={[objectToString]}>
210
+ <select multiple={true} value={[objectToString]} onChange={noop}>
211
<option value="monkey">A monkey!</option>
212
<option value="giraffe">A giraffe!</option>
213
<option value="gorilla">A gorilla!</option>
@@ -285,7 +289,7 @@ describe('ReactDOMSelect', function() {
289
290
it('should remember value when switching to uncontrolled', function() {
291
var stub =
288
- <select value={'giraffe'}>
292
+ <select value={'giraffe'} onChange={noop}>
293
<option value="monkey">A monkey!</option>
294
<option value="giraffe">A giraffe!</option>
295
<option value="gorilla">A gorilla!</option>
@@ -308,7 +312,7 @@ describe('ReactDOMSelect', function() {
312
313
it('should remember updated value when switching to uncontrolled', function() {
314
var stub =
311
- <select value={'giraffe'}>
315
+ <select value={'giraffe'} onChange={noop}>
316
<option value="monkey">A monkey!</option>
317
<option value="giraffe">A giraffe!</option>
318
<option value="gorilla">A gorilla!</option>
@@ -318,7 +322,10 @@ describe('ReactDOMSelect', function() {
322
stub = React.render(stub, container);
323
var node = React.findDOMNode(stub);
324
321
- React.render(<select value="gorilla">{options}</select>, container);
325
+ React.render(
326
+ <select value="gorilla" onChange={noop}>{options}</select>,
327
+ container
328
+ );
329
330
expect(node.options[0].selected).toBe(false); // monkey
331
expect(node.options[1].selected).toBe(false); // giraffe
@@ -358,7 +365,7 @@ describe('ReactDOMSelect', function() {
365
366
it('should support server-side rendering', function() {
367
var stub =
361
- <select value="giraffe">
368
+ <select value="giraffe" onChange={noop}>
369
<option value="monkey">A monkey!</option>
370
<option value="giraffe">A giraffe!</option>
371
<option value="gorilla">A gorilla!</option>
@@ -384,7 +391,7 @@ describe('ReactDOMSelect', function() {
391
392
it('should support server-side rendering with multiple', function() {
393
var stub =
387
- <select multiple={true} value={['giraffe', 'gorilla']}>
394
+ <select multiple={true} value={['giraffe', 'gorilla']} onChange={noop}>
395
<option value="monkey">A monkey!</option>
396
<option value="giraffe">A giraffe!</option>
397
<option value="gorilla">A gorilla!</option>
src/renderers/shared/reconciler/__tests__/ReactMultiChildText-test.js
+3
@@ -84,6 +84,7 @@ var expectChildren = function(d, children) {
84
*/
85
describe('ReactMultiChildText', function() {
86
it('should correctly handle all possible children for render and update', function() {
87
+ spyOn(console, 'error');
88
testAllPermutations([
89
// basic values
90
undefined, [],
@@ -184,6 +185,8 @@ describe('ReactMultiChildText', function() {
185
[true, <div>{1.2}{''}{<div />}{'foo'}</div>, true, 1.2], [<div />, '1.2'],
186
['', 'foo', <div>{true}{<div />}{1.2}{''}</div>, 'foo'], ['', 'foo', <div />, 'foo'],
187
]);
188
+ expect(console.error.calls.length).toBe(1);
189
+ expect(console.error.calls[0].args[0]).toContain('Warning: Each child in an array or iterator should have a unique "key" prop.');
190
});
191
192
it('should throw if rendering both HTML and children', function() {
src/shared/utils/__tests__/traverseAllChildren-test.js
+4
@@ -64,6 +64,7 @@ describe('traverseAllChildren', function() {
64
});
65
66
it('should treat single child in array as expected', function() {
67
+ spyOn(console, 'error');
68
var traverseContext = [];
69
var traverseFn =
70
jasmine.createSpy().andCallFake(function(context, kid, key, index) {
@@ -79,6 +80,8 @@ describe('traverseAllChildren', function() {
80
'.0'
81
);
82
expect(traverseContext.length).toEqual(1);
83
+ expect(console.error.calls.length).toBe(1);
84
+ expect(console.error.calls[0].args[0]).toContain('Warning: Each child in an array or iterator should have a unique "key" prop.');
85
});
86
87
it('should be called for each child', function() {
@@ -328,6 +331,7 @@ describe('traverseAllChildren', function() {
331
traverseContext[2],
332
'.2'
333
);
334
+
335
});
336
337
it('should be called for each child in an iterable with keys', function() {