Use console.error to show stack trace in console
Better version of #3277. Test Plan: jest, grunt test
Ben Alpert committed
Mar 17, 2015 at 13:39 UTC
e791fccf5833450fff2929416174d489b9785e37
32 files changed
+427
-442
src/addons/__tests__/ReactFragment-test.js
+20
-20
@@ -22,14 +22,14 @@ describe('ReactFragment', function() {
22
});
23
24
it('should warn if a plain object is used as a child', function() {
25
- spyOn(console, 'warn');
25
+ spyOn(console, 'error');
26
var children = {
27
x: <span />,
28
y: <span />
29
};
30
<div>{children}</div>;
31
- expect(console.warn.calls.length).toBe(1);
32
- expect(console.warn.calls[0].args[0]).toContain(
31
+ expect(console.error.calls.length).toBe(1);
32
+ expect(console.error.calls[0].args[0]).toContain(
33
'Any use of a keyed object'
34
);
35
// Only warn once for the same set of children
@@ -38,28 +38,28 @@ describe('ReactFragment', function() {
38
y: <span />
39
};
40
<div>{sameChildren}</div>;
41
- expect(console.warn.calls.length).toBe(1);
41
+ expect(console.error.calls.length).toBe(1);
42
});
43
44
it('should warn if a plain object even if it is deep', function() {
45
- spyOn(console, 'warn');
45
+ spyOn(console, 'error');
46
var children = {
47
x: <span />,
48
y: <span />,
49
z: <span />
50
};
51
var element = <div>{[children]}</div>;
52
- expect(console.warn.calls.length).toBe(0);
52
+ expect(console.error.calls.length).toBe(0);
53
var container = document.createElement('div');
54
React.render(element, container);
55
- expect(console.warn.calls.length).toBe(1);
56
- expect(console.warn.calls[0].args[0]).toContain(
55
+ expect(console.error.calls.length).toBe(1);
56
+ expect(console.error.calls[0].args[0]).toContain(
57
'Any use of a keyed object'
58
);
59
});
60
61
it('should warn if accessing any property on a fragment', function() {
62
- spyOn(console, 'warn');
62
+ spyOn(console, 'error');
63
var children = {
64
x: <span />,
65
y: <span />
@@ -67,35 +67,35 @@ describe('ReactFragment', function() {
67
var frag = ReactFragment.create(children);
68
frag.x;
69
frag.y = 10;
70
- expect(console.warn.calls.length).toBe(1);
71
- expect(console.warn.calls[0].args[0]).toContain(
70
+ expect(console.error.calls.length).toBe(1);
71
+ expect(console.error.calls[0].args[0]).toContain(
72
'A ReactFragment is an opaque type'
73
);
74
});
75
76
it('should warn if passing null to createFragment', function() {
77
- spyOn(console, 'warn');
77
+ spyOn(console, 'error');
78
ReactFragment.create(null);
79
- expect(console.warn.calls.length).toBe(1);
80
- expect(console.warn.calls[0].args[0]).toContain(
79
+ expect(console.error.calls.length).toBe(1);
80
+ expect(console.error.calls[0].args[0]).toContain(
81
'React.addons.createFragment only accepts a single object.'
82
);
83
});
84
85
it('should warn if passing an array to createFragment', function() {
86
- spyOn(console, 'warn');
86
+ spyOn(console, 'error');
87
ReactFragment.create([]);
88
- expect(console.warn.calls.length).toBe(1);
89
- expect(console.warn.calls[0].args[0]).toContain(
88
+ expect(console.error.calls.length).toBe(1);
89
+ expect(console.error.calls[0].args[0]).toContain(
90
'React.addons.createFragment only accepts a single object.'
91
);
92
});
93
94
it('should warn if passing a ReactElement to createFragment', function() {
95
- spyOn(console, 'warn');
95
+ spyOn(console, 'error');
96
ReactFragment.create(<div />);
97
- expect(console.warn.calls.length).toBe(1);
98
- expect(console.warn.calls[0].args[0]).toContain(
97
+ expect(console.error.calls.length).toBe(1);
98
+ expect(console.error.calls[0].args[0]).toContain(
99
'React.addons.createFragment does not accept a ReactElement without a ' +
100
'wrapper object.'
101
);
src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js
+2
-2
@@ -26,7 +26,7 @@ describe('ReactCSSTransitionGroup', function() {
26
mocks = require('mocks');
27
28
container = document.createElement('div');
29
- spyOn(console, 'warn');
29
+ spyOn(console, 'error');
30
});
31
32
it('should warn after time with no transitionend', function() {
@@ -60,7 +60,7 @@ describe('ReactCSSTransitionGroup', function() {
60
}
61
62
expect(React.findDOMNode(a).childNodes.length).toBe(2);
63
- expect(console.warn.argsForCall.length).toBe(1);
63
+ expect(console.error.argsForCall.length).toBe(1);
64
});
65
66
it('should keep both sets of DOM nodes around', function() {
src/browser/__tests__/ReactBrowserEventEmitter-test.js
+3
-3
@@ -262,12 +262,12 @@ describe('ReactBrowserEventEmitter', function() {
262
ON_CLICK_KEY,
263
recordID.bind(null, getID(GRANDPARENT))
264
);
265
- spyOn(console, 'warn');
265
+ spyOn(console, 'error');
266
ReactTestUtils.Simulate.click(CHILD);
267
expect(idCallOrder.length).toBe(1);
268
expect(idCallOrder[0]).toBe(getID(CHILD));
269
- expect(console.warn.calls.length).toEqual(1);
270
- expect(console.warn.calls[0].args[0]).toBe(
269
+ expect(console.error.calls.length).toEqual(1);
270
+ expect(console.error.calls[0].args[0]).toBe(
271
'Warning: Returning `false` from an event handler is deprecated and ' +
272
'will be ignored in a future release. Instead, manually call ' +
273
'e.stopPropagation() or e.preventDefault(), as appropriate.'
src/browser/__tests__/ReactDOM-test.js
+2
-2
@@ -113,10 +113,10 @@ describe('ReactDOM', function() {
113
});
114
115
it('allow React.DOM factories to be called without warnings', function() {
116
- spyOn(console, 'warn');
116
+ spyOn(console, 'error');
117
var element = React.DOM.div();
118
expect(element.type).toBe('div');
119
- expect(console.warn.argsForCall.length).toBe(0);
119
+ expect(console.error.argsForCall.length).toBe(0);
120
});
121
122
});
src/browser/eventPlugins/__tests__/AnalyticsEventPlugin-test.js
+5
-5
@@ -53,7 +53,7 @@ describe('AnalyticsEventPlugin', function() {
53
'ChangeEventPlugin': ChangeEventPlugin
54
});
55
56
- spyOn(console, 'warn');
56
+ spyOn(console, 'error');
57
});
58
59
it('should count events correctly', function() {
@@ -107,8 +107,8 @@ describe('AnalyticsEventPlugin', function() {
107
108
it('warn on no callback', function() {
109
AnalyticsEventPluginFactory.createAnalyticsPlugin(null);
110
- expect(console.warn.calls.length).toBe(1);
111
- expect(console.warn.argsForCall[0][0]).toBe(
110
+ expect(console.error.calls.length).toBe(1);
111
+ expect(console.error.argsForCall[0][0]).toBe(
112
'Warning: createAnalyticsPlugin(...): You must provide a callback.'
113
);
114
});
@@ -138,8 +138,8 @@ describe('AnalyticsEventPlugin', function() {
138
139
ReactTestUtils.SimulateNative.click(renderedComponent.refs.testDiv);
140
141
- expect(console.warn.calls.length).toBe(1);
142
- expect(console.warn.argsForCall[0][0]).toBe(
141
+ expect(console.error.calls.length).toBe(1);
142
+ expect(console.error.argsForCall[0][0]).toBe(
143
'Warning: Invalid analyticsEvent:123 for analyticsID:test_invalid_events'
144
);
145
});
src/browser/server/__tests__/ReactServerRendering-test.js
+2
-2
@@ -48,7 +48,7 @@ describe('ReactServerRendering', function() {
48
49
var DOMProperty = require('DOMProperty');
50
ID_ATTRIBUTE_NAME = DOMProperty.ID_ATTRIBUTE_NAME;
51
- spyOn(console, 'warn');
51
+ spyOn(console, 'error');
52
});
53
54
describe('renderToString', function() {
@@ -219,7 +219,7 @@ describe('ReactServerRendering', function() {
219
element.innerHTML = lastMarkup;
220
var instance = React.render(<TestComponent name="y" />, element);
221
expect(mountCount).toEqual(4);
222
- expect(console.warn.argsForCall.length).toBe(1);
222
+ expect(console.error.argsForCall.length).toBe(1);
223
expect(element.innerHTML.length > 0).toBe(true);
224
expect(element.innerHTML).not.toEqual(lastMarkup);
225
src/browser/ui/__tests__/ReactDOMComponent-test.js
+27
-27
@@ -344,18 +344,18 @@ describe('ReactDOMComponent', function() {
344
});
345
346
it("should warn against children for void elements", function() {
347
- spyOn(console, 'warn');
347
+ spyOn(console, 'error');
348
349
var container = document.createElement('div');
350
351
React.render(<input>children</input>, container);
352
353
- expect(console.warn.argsForCall.length).toBe(1);
354
- expect(console.warn.argsForCall[0][0]).toContain('void element');
353
+ expect(console.error.argsForCall.length).toBe(1);
354
+ expect(console.error.argsForCall[0][0]).toContain('void element');
355
});
356
357
it("should warn against dangerouslySetInnerHTML for void elements", function() {
358
- spyOn(console, 'warn');
358
+ spyOn(console, 'error');
359
360
var container = document.createElement('div');
361
@@ -364,12 +364,12 @@ describe('ReactDOMComponent', function() {
364
container
365
);
366
367
- expect(console.warn.argsForCall.length).toBe(1);
368
- expect(console.warn.argsForCall[0][0]).toContain('void element');
367
+ expect(console.error.argsForCall.length).toBe(1);
368
+ expect(console.error.argsForCall[0][0]).toContain('void element');
369
});
370
371
it("should treat menuitem as a void element but still create the closing tag", function() {
372
- spyOn(console, 'warn');
372
+ spyOn(console, 'error');
373
374
var container = document.createElement('div');
375
@@ -379,8 +379,8 @@ describe('ReactDOMComponent', function() {
379
380
React.render(<menuitem>children</menuitem>, container);
381
382
- expect(console.warn.argsForCall.length).toBe(1);
383
- expect(console.warn.argsForCall[0][0]).toContain('void element');
382
+ expect(console.error.argsForCall.length).toBe(1);
383
+ expect(console.error.argsForCall[0][0]).toContain('void element');
384
});
385
386
it("should validate against multiple children props", function() {
@@ -394,10 +394,10 @@ describe('ReactDOMComponent', function() {
394
395
it('should validate against use of innerHTML', function() {
396
397
- spyOn(console, 'warn');
397
+ spyOn(console, 'error');
398
mountComponent({innerHTML: '<span>Hi Jim!</span>'});
399
- expect(console.warn.argsForCall.length).toBe(1);
400
- expect(console.warn.argsForCall[0][0]).toContain(
399
+ expect(console.error.argsForCall.length).toBe(1);
400
+ expect(console.error.argsForCall[0][0]).toContain(
401
'Directly setting property `innerHTML` is not permitted. '
402
);
403
});
@@ -423,10 +423,10 @@ describe('ReactDOMComponent', function() {
423
});
424
425
it("should warn about contentEditable and children", function() {
426
- spyOn(console, 'warn');
426
+ spyOn(console, 'error');
427
mountComponent({contentEditable: true, children: ''});
428
- expect(console.warn.argsForCall.length).toBe(1);
429
- expect(console.warn.argsForCall[0][0]).toContain('contentEditable');
428
+ expect(console.error.argsForCall.length).toBe(1);
429
+ expect(console.error.argsForCall[0][0]).toContain('contentEditable');
430
});
431
432
it("should validate against invalid styles", function() {
@@ -503,17 +503,17 @@ describe('ReactDOMComponent', function() {
503
});
504
505
it("should warn against children for void elements", function() {
506
- spyOn(console, 'warn');
506
+ spyOn(console, 'error');
507
508
React.render(<input />, container);
509
React.render(<input>children</input>, container);
510
511
- expect(console.warn.argsForCall.length).toBe(1);
512
- expect(console.warn.argsForCall[0][0]).toContain('void element');
511
+ expect(console.error.argsForCall.length).toBe(1);
512
+ expect(console.error.argsForCall[0][0]).toContain('void element');
513
});
514
515
it("should warn against dangerouslySetInnerHTML for void elements", function() {
516
- spyOn(console, 'warn');
516
+ spyOn(console, 'error');
517
518
React.render(<input />, container);
519
React.render(
@@ -521,8 +521,8 @@ describe('ReactDOMComponent', function() {
521
container
522
);
523
524
- expect(console.warn.argsForCall.length).toBe(1);
525
- expect(console.warn.argsForCall[0][0]).toContain('void element');
524
+ expect(console.error.argsForCall.length).toBe(1);
525
+ expect(console.error.argsForCall[0][0]).toContain('void element');
526
});
527
528
it("should validate against multiple children props", function() {
@@ -540,13 +540,13 @@ describe('ReactDOMComponent', function() {
540
});
541
542
it("should warn about contentEditable and children", function() {
543
- spyOn(console, 'warn');
543
+ spyOn(console, 'error');
544
React.render(
545
<div contentEditable><div /></div>,
546
container
547
);
548
- expect(console.warn.argsForCall.length).toBe(1);
549
- expect(console.warn.argsForCall[0][0]).toContain('contentEditable');
548
+ expect(console.error.argsForCall.length).toBe(1);
549
+ expect(console.error.argsForCall[0][0]).toContain('contentEditable');
550
});
551
552
it("should validate against invalid styles", function() {
@@ -620,10 +620,10 @@ describe('ReactDOMComponent', function() {
620
var React = require('React');
621
var ReactTestUtils = require('ReactTestUtils');
622
623
- spyOn(console, 'warn');
623
+ spyOn(console, 'error');
624
ReactTestUtils.renderIntoDocument(<div onScroll={function() {}} />);
625
- expect(console.warn.calls.length).toBe(1);
626
- expect(console.warn.mostRecentCall.args[0]).toBe(
625
+ expect(console.error.calls.length).toBe(1);
626
+ expect(console.error.mostRecentCall.args[0]).toBe(
627
'Warning: This browser doesn\'t support the `onScroll` event'
628
);
629
});
src/browser/ui/__tests__/ReactMount-test.js
+9
-9
@@ -132,35 +132,35 @@ describe('ReactMount', function() {
132
var container = document.createElement('container');
133
container.innerHTML = React.renderToString(<div />) + ' ';
134
135
- console.warn = mocks.getMockFunction();
135
+ console.error = mocks.getMockFunction();
136
ReactMount.render(<div />, container);
137
- expect(console.warn.mock.calls.length).toBe(1);
137
+ expect(console.error.mock.calls.length).toBe(1);
138
139
container.innerHTML = ' ' + React.renderToString(<div />);
140
141
- console.warn = mocks.getMockFunction();
141
+ console.error = mocks.getMockFunction();
142
ReactMount.render(<div />, container);
143
- expect(console.warn.mock.calls.length).toBe(1);
143
+ expect(console.error.mock.calls.length).toBe(1);
144
});
145
146
it('should not warn if mounting into non-empty node', function() {
147
var container = document.createElement('container');
148
container.innerHTML = '<div></div>';
149
150
- console.warn = mocks.getMockFunction();
150
+ console.error = mocks.getMockFunction();
151
ReactMount.render(<div />, container);
152
- expect(console.warn.mock.calls.length).toBe(0);
152
+ expect(console.error.mock.calls.length).toBe(0);
153
});
154
155
it('should warn when mounting into document.body', function () {
156
var iFrame = document.createElement('iframe');
157
document.body.appendChild(iFrame);
158
- spyOn(console, 'warn');
158
+ spyOn(console, 'error');
159
160
ReactMount.render(<div />, iFrame.contentDocument.body);
161
162
- expect(console.warn.calls.length).toBe(1);
163
- expect(console.warn.calls[0].args[0]).toContain(
162
+ expect(console.error.calls.length).toBe(1);
163
+ expect(console.error.calls[0].args[0]).toContain(
164
'Rendering components directly into document.body is discouraged'
165
);
166
});
src/browser/ui/dom/__tests__/CSSPropertyOperations-test.js
+17
-17
@@ -109,18 +109,18 @@ describe('CSSPropertyOperations', function() {
109
});
110
111
it('should warn when using hyphenated style names', function() {
112
- spyOn(console, 'warn');
112
+ spyOn(console, 'error');
113
114
expect(CSSPropertyOperations.createMarkupForStyles({
115
'background-color': 'crimson'
116
})).toBe('background-color:crimson;');
117
118
- expect(console.warn.argsForCall.length).toBe(1);
119
- expect(console.warn.argsForCall[0][0]).toContain('backgroundColor');
118
+ expect(console.error.argsForCall.length).toBe(1);
119
+ expect(console.error.argsForCall[0][0]).toContain('backgroundColor');
120
});
121
122
it('should warn when updating hyphenated style names', function() {
123
- spyOn(console, 'warn');
123
+ spyOn(console, 'error');
124
125
var root = document.createElement('div');
126
var styles = {
@@ -131,13 +131,13 @@ describe('CSSPropertyOperations', function() {
131
React.render(<div />, root);
132
React.render(<div style={styles} />, root);
133
134
- expect(console.warn.argsForCall.length).toBe(2);
135
- expect(console.warn.argsForCall[0][0]).toContain('msTransform');
136
- expect(console.warn.argsForCall[1][0]).toContain('WebkitTransform');
134
+ expect(console.error.argsForCall.length).toBe(2);
135
+ expect(console.error.argsForCall[0][0]).toContain('msTransform');
136
+ expect(console.error.argsForCall[1][0]).toContain('WebkitTransform');
137
});
138
139
it('warns when miscapitalizing vendored style names', function() {
140
- spyOn(console, 'warn');
140
+ spyOn(console, 'error');
141
142
CSSPropertyOperations.createMarkupForStyles({
143
msTransform: 'translate3d(0, 0, 0)',
@@ -146,15 +146,15 @@ describe('CSSPropertyOperations', function() {
146
});
147
148
// msTransform is correct already and shouldn't warn
149
- expect(console.warn.argsForCall.length).toBe(2);
150
- expect(console.warn.argsForCall[0][0]).toContain('oTransform');
151
- expect(console.warn.argsForCall[0][0]).toContain('OTransform');
152
- expect(console.warn.argsForCall[1][0]).toContain('webkitTransform');
153
- expect(console.warn.argsForCall[1][0]).toContain('WebkitTransform');
149
+ expect(console.error.argsForCall.length).toBe(2);
150
+ expect(console.error.argsForCall[0][0]).toContain('oTransform');
151
+ expect(console.error.argsForCall[0][0]).toContain('OTransform');
152
+ expect(console.error.argsForCall[1][0]).toContain('webkitTransform');
153
+ expect(console.error.argsForCall[1][0]).toContain('WebkitTransform');
154
});
155
156
it('should warn about style having a trailing semicolon', function() {
157
- spyOn(console, 'warn');
157
+ spyOn(console, 'error');
158
159
CSSPropertyOperations.createMarkupForStyles({
160
fontFamily: 'Helvetica, arial',
@@ -163,8 +163,8 @@ describe('CSSPropertyOperations', function() {
163
color: 'red; '
164
});
165
166
- expect(console.warn.calls.length).toBe(2);
167
- expect(console.warn.argsForCall[0][0]).toContain('Try "backgroundColor: blue" instead');
168
- expect(console.warn.argsForCall[1][0]).toContain('Try "color: red" instead');
166
+ expect(console.error.calls.length).toBe(2);
167
+ expect(console.error.argsForCall[0][0]).toContain('Try "backgroundColor: blue" instead');
168
+ expect(console.error.argsForCall[1][0]).toContain('Try "color: red" instead');
169
});
170
});
src/browser/ui/dom/__tests__/DOMPropertyOperations-test.js
+6
-6
@@ -55,23 +55,23 @@ describe('DOMPropertyOperations', function() {
55
});
56
57
it('should warn about incorrect casing', function() {
58
- spyOn(console, 'warn');
58
+ spyOn(console, 'error');
59
expect(DOMPropertyOperations.createMarkupForProperty(
60
'tabindex',
61
'1'
62
)).toBe(null);
63
- expect(console.warn.argsForCall.length).toBe(1);
64
- expect(console.warn.argsForCall[0][0]).toContain('tabIndex');
63
+ expect(console.error.argsForCall.length).toBe(1);
64
+ expect(console.error.argsForCall[0][0]).toContain('tabIndex');
65
});
66
67
it('should warn about class', function() {
68
- spyOn(console, 'warn');
68
+ spyOn(console, 'error');
69
expect(DOMPropertyOperations.createMarkupForProperty(
70
'class',
71
'muffins'
72
)).toBe(null);
73
- expect(console.warn.argsForCall.length).toBe(1);
74
- expect(console.warn.argsForCall[0][0]).toContain('className');
73
+ expect(console.error.argsForCall.length).toBe(1);
74
+ expect(console.error.argsForCall[0][0]).toContain('className');
75
});
76
77
it('should create markup for boolean properties', function() {
src/browser/ui/dom/components/__tests__/ReactDOMInput-test.js
+12
-27
@@ -26,7 +26,7 @@ describe('ReactDOMInput', function() {
26
React = require('React');
27
ReactLink = require('ReactLink');
28
ReactTestUtils = require('ReactTestUtils');
29
- spyOn(console, 'warn');
29
+ spyOn(console, 'error');
30
});
31
32
it('should display `defaultValue` of number 0', function() {
@@ -216,34 +216,29 @@ describe('ReactDOMInput', function() {
216
it('should warn with value and no onChange handler', function() {
217
var link = new ReactLink('yolo', mocks.getMockFunction());
218
ReactTestUtils.renderIntoDocument(<input type="text" valueLink={link} />);
219
- expect(console.warn.argsForCall.length).toBe(0);
219
+ expect(console.error.argsForCall.length).toBe(0);
220
221
ReactTestUtils.renderIntoDocument(
222
<input type="text" value="zoink" onChange={mocks.getMockFunction()} />
223
);
224
- expect(console.warn.argsForCall.length).toBe(0);
224
+ expect(console.error.argsForCall.length).toBe(0);
225
ReactTestUtils.renderIntoDocument(<input type="text" value="zoink" />);
226
- expect(console.warn.argsForCall.length).toBe(1);
226
+ expect(console.error.argsForCall.length).toBe(1);
227
});
228
229
it('should warn with value and no onChange handler and readOnly specified', function() {
230
ReactTestUtils.renderIntoDocument(
231
<input type="text" value="zoink" readOnly={true} />
232
);
233
- expect(console.warn.argsForCall.length).toBe(0);
233
+ expect(console.error.argsForCall.length).toBe(0);
234
235
ReactTestUtils.renderIntoDocument(
236
<input type="text" value="zoink" readOnly={false} />
237
);
238
- expect(console.warn.argsForCall.length).toBe(1);
238
+ expect(console.error.argsForCall.length).toBe(1);
239
});
240
241
it('should throw if both value and valueLink are provided', function() {
242
- // Silences console.error messages
243
- // ReactErrorUtils.guard is applied to all methods of a React component
244
- // and calls console.error in __DEV__ (true for test environment)
245
- spyOn(console, 'error');
246
-
242
var node = document.createElement('div');
243
var link = new ReactLink('yolo', mocks.getMockFunction());
244
var instance = <input type="text" valueLink={link} />;
@@ -285,7 +280,7 @@ describe('ReactDOMInput', function() {
280
var node = document.createElement('div');
281
var link = new ReactLink(true, mocks.getMockFunction());
282
React.render(<input type="checkbox" checkedLink={link} />, node);
288
- expect(console.warn.argsForCall.length).toBe(0);
283
+ expect(console.error.argsForCall.length).toBe(0);
284
285
ReactTestUtils.renderIntoDocument(
286
<input
@@ -294,35 +289,30 @@ describe('ReactDOMInput', function() {
289
onChange={mocks.getMockFunction()}
290
/>
291
);
297
- expect(console.warn.argsForCall.length).toBe(0);
292
+ expect(console.error.argsForCall.length).toBe(0);
293
294
ReactTestUtils.renderIntoDocument(
295
<input type="checkbox" checked="false" readOnly={true} />
296
);
302
- expect(console.warn.argsForCall.length).toBe(0);
297
+ expect(console.error.argsForCall.length).toBe(0);
298
299
ReactTestUtils.renderIntoDocument(<input type="checkbox" checked="false" />);
305
- expect(console.warn.argsForCall.length).toBe(1);
300
+ expect(console.error.argsForCall.length).toBe(1);
301
});
302
303
it('should warn with checked and no onChange handler with readOnly specified', function() {
304
ReactTestUtils.renderIntoDocument(
305
<input type="checkbox" checked="false" readOnly={true} />
306
);
312
- expect(console.warn.argsForCall.length).toBe(0);
307
+ expect(console.error.argsForCall.length).toBe(0);
308
309
ReactTestUtils.renderIntoDocument(
310
<input type="checkbox" checked="false" readOnly={false} />
311
);
317
- expect(console.warn.argsForCall.length).toBe(1);
312
+ expect(console.error.argsForCall.length).toBe(1);
313
});
314
315
it('should throw if both checked and checkedLink are provided', function() {
321
- // Silences console.error messages
322
- // ReactErrorUtils.guard is applied to all methods of a React component
323
- // and calls console.error in __DEV__ (true for test environment)
324
- spyOn(console, 'error');
325
-
316
var node = document.createElement('div');
317
var link = new ReactLink(true, mocks.getMockFunction());
318
var instance = <input type="checkbox" checkedLink={link} />;
@@ -345,11 +335,6 @@ describe('ReactDOMInput', function() {
335
});
336
337
it('should throw if both checkedLink and valueLink are provided', function() {
348
- // Silences console.error messages
349
- // ReactErrorUtils.guard is applied to all methods of a React component
350
- // and calls console.error in __DEV__ (true for test environment)
351
- spyOn(console, 'error');
352
-
338
var node = document.createElement('div');
339
var link = new ReactLink(true, mocks.getMockFunction());
340
var instance = <input type="checkbox" checkedLink={link} />;
src/browser/ui/dom/components/__tests__/ReactDOMTextarea-test.js
+11
-11
@@ -154,13 +154,13 @@ describe('ReactDOMTextarea', function() {
154
});
155
156
it('should treat children like `defaultValue`', function() {
157
- spyOn(console, 'warn');
157
+ spyOn(console, 'error');
158
159
var stub = <textarea>giraffe</textarea>;
160
stub = renderTextarea(stub);
161
var node = React.findDOMNode(stub);
162
163
- expect(console.warn.argsForCall.length).toBe(1);
163
+ expect(console.error.argsForCall.length).toBe(1);
164
expect(node.value).toBe('giraffe');
165
166
// Changing children should do nothing, it functions like `defaultValue`.
@@ -169,33 +169,33 @@ describe('ReactDOMTextarea', function() {
169
});
170
171
it('should allow numbers as children', function() {
172
- spyOn(console, 'warn');
172
+ spyOn(console, 'error');
173
var node = React.findDOMNode(renderTextarea(<textarea>{17}</textarea>));
174
- expect(console.warn.argsForCall.length).toBe(1);
174
+ expect(console.error.argsForCall.length).toBe(1);
175
expect(node.value).toBe('17');
176
});
177
178
it('should allow booleans as children', function() {
179
- spyOn(console, 'warn');
179
+ spyOn(console, 'error');
180
var node = React.findDOMNode(renderTextarea(<textarea>{false}</textarea>));
181
- expect(console.warn.argsForCall.length).toBe(1);
181
+ expect(console.error.argsForCall.length).toBe(1);
182
expect(node.value).toBe('false');
183
});
184
185
it('should allow objects as children', function() {
186
- spyOn(console, 'warn');
186
+ spyOn(console, 'error');
187
var obj = {
188
toString: function() {
189
return "sharkswithlasers";
190
}
191
};
192
var node = React.findDOMNode(renderTextarea(<textarea>{obj}</textarea>));
193
- expect(console.warn.argsForCall.length).toBe(1);
193
+ expect(console.error.argsForCall.length).toBe(1);
194
expect(node.value).toBe('sharkswithlasers');
195
});
196
197
it('should throw with multiple or invalid children', function() {
198
- spyOn(console, 'warn');
198
+ spyOn(console, 'error');
199
200
expect(function() {
201
ReactTestUtils.renderIntoDocument(
@@ -203,7 +203,7 @@ describe('ReactDOMTextarea', function() {
203
);
204
}).toThrow();
205
206
- expect(console.warn.argsForCall.length).toBe(1);
206
+ expect(console.error.argsForCall.length).toBe(1);
207
208
var node;
209
expect(function() {
@@ -212,7 +212,7 @@ describe('ReactDOMTextarea', function() {
212
213
expect(node.value).toBe('[object Object]');
214
215
- expect(console.warn.argsForCall.length).toBe(2);
215
+ expect(console.error.argsForCall.length).toBe(2);
216
});
217
218
it('should support ReactLink', function() {
src/classic/__tests__/ReactContextValidator-test.js
+12
-12
@@ -32,7 +32,7 @@ describe('ReactContextValidator', function() {
32
reactComponentExpect = require('reactComponentExpect');
33
mocks = require('mocks');
34
35
- spyOn(console, 'warn');
35
+ spyOn(console, 'error');
36
});
37
38
// TODO: This behavior creates a runtime dependency on propTypes. We should
@@ -145,8 +145,8 @@ describe('ReactContextValidator', function() {
145
146
ReactTestUtils.renderIntoDocument(<Component />);
147
148
- expect(console.warn.argsForCall.length).toBe(1);
149
- expect(console.warn.argsForCall[0][0]).toBe(
148
+ expect(console.error.argsForCall.length).toBe(1);
149
+ expect(console.error.argsForCall[0][0]).toBe(
150
'Warning: Failed Context Types: ' +
151
'Required context `foo` was not specified in `Component`.'
152
);
@@ -172,7 +172,7 @@ describe('ReactContextValidator', function() {
172
);
173
174
// Previous call should not error
175
- expect(console.warn.argsForCall.length).toBe(1);
175
+ expect(console.error.argsForCall.length).toBe(1);
176
177
var ComponentInFooNumberContext = React.createClass({
178
childContextTypes: {
@@ -192,8 +192,8 @@ describe('ReactContextValidator', function() {
192
193
ReactTestUtils.renderIntoDocument(<ComponentInFooNumberContext fooValue={123} />);
194
195
- expect(console.warn.argsForCall.length).toBe(2);
196
- expect(console.warn.argsForCall[1][0]).toBe(
195
+ expect(console.error.argsForCall.length).toBe(2);
196
+ expect(console.error.argsForCall[1][0]).toBe(
197
'Warning: Failed Context Types: ' +
198
'Invalid context `foo` of type `number` supplied ' +
199
'to `Component`, expected `string`.' +
@@ -218,20 +218,20 @@ describe('ReactContextValidator', function() {
218
});
219
220
ReactTestUtils.renderIntoDocument(<Component testContext={{bar: 123}} />);
221
- expect(console.warn.argsForCall.length).toBe(2);
222
- expect(console.warn.argsForCall[0][0]).toBe(
221
+ expect(console.error.argsForCall.length).toBe(2);
222
+ expect(console.error.argsForCall[0][0]).toBe(
223
'Warning: Failed Context Types: ' +
224
'Required child context `foo` was not specified in `Component`.'
225
);
226
- expect(console.warn.argsForCall[1][0]).toBe(
226
+ expect(console.error.argsForCall[1][0]).toBe(
227
'Warning: Failed Context Types: ' +
228
'Required child context `foo` was not specified in `Component`.'
229
);
230
231
ReactTestUtils.renderIntoDocument(<Component testContext={{foo: 123}} />);
232
233
- expect(console.warn.argsForCall.length).toBe(4);
234
- expect(console.warn.argsForCall[3][0]).toBe(
233
+ expect(console.error.argsForCall.length).toBe(4);
234
+ expect(console.error.argsForCall[3][0]).toBe(
235
'Warning: Failed Context Types: ' +
236
'Invalid child context `foo` of type `number` ' +
237
'supplied to `Component`, expected `string`.'
@@ -246,7 +246,7 @@ describe('ReactContextValidator', function() {
246
);
247
248
// Previous calls should not log errors
249
- expect(console.warn.argsForCall.length).toBe(4);
249
+ expect(console.error.argsForCall.length).toBe(4);
250
});
251
252
});
src/classic/class/__tests__/ReactBind-test.js
+5
-5
@@ -125,7 +125,7 @@ describe('autobinding', function() {
125
});
126
127
it('warns if you try to bind to this', function() {
128
- spyOn(console, 'warn');
128
+ spyOn(console, 'error');
129
130
var TestBindComponent = React.createClass({
131
handleClick: function() { },
@@ -136,8 +136,8 @@ describe('autobinding', function() {
136
137
ReactTestUtils.renderIntoDocument(<TestBindComponent />)
138
139
- expect(console.warn.argsForCall.length).toBe(1);
140
- expect(console.warn.argsForCall[0][0]).toBe(
139
+ expect(console.error.argsForCall.length).toBe(1);
140
+ expect(console.error.argsForCall[0][0]).toBe(
141
'Warning: bind(): You are binding a component method to the component. ' +
142
'React does this for you automatically in a high-performance ' +
143
'way, so you can safely remove this call. See TestBindComponent'
@@ -145,7 +145,7 @@ describe('autobinding', function() {
145
});
146
147
it('does not warn if you pass an auto-bound method to setState', function() {
148
- spyOn(console, 'warn');
148
+ spyOn(console, 'error');
149
150
var TestBindComponent = React.createClass({
151
getInitialState: function() {
@@ -164,7 +164,7 @@ describe('autobinding', function() {
164
165
ReactTestUtils.renderIntoDocument(<TestBindComponent />)
166
167
- expect(console.warn.argsForCall.length).toBe(0);
167
+ expect(console.error.argsForCall.length).toBe(0);
168
});
169
170
});
src/classic/class/__tests__/ReactClass-test.js
+32
-32
@@ -21,7 +21,7 @@ describe('ReactClass-spec', function() {
21
beforeEach(function() {
22
React = require('React');
23
ReactTestUtils = require('ReactTestUtils');
24
- spyOn(console, 'warn');
24
+ spyOn(console, 'error');
25
});
26
27
it('should throw when `render` is not specified', function() {
@@ -56,21 +56,21 @@ describe('ReactClass-spec', function() {
56
}
57
});
58
expect(TestComponent.type).toBe(TestComponent);
59
- expect(console.warn.argsForCall.length).toBe(1);
60
- expect(console.warn.argsForCall[0][0]).toBe(
59
+ expect(console.error.argsForCall.length).toBe(1);
60
+ expect(console.error.argsForCall[0][0]).toBe(
61
'Warning: TestComponent.type is deprecated. Use TestComponent ' +
62
'directly to access the class.'
63
);
64
// Warn once per class
65
expect(SecondTestComponent.type).toBe(SecondTestComponent);
66
- expect(console.warn.argsForCall.length).toBe(2);
67
- expect(console.warn.argsForCall[1][0]).toBe(
66
+ expect(console.error.argsForCall.length).toBe(2);
67
+ expect(console.error.argsForCall[1][0]).toBe(
68
'Warning: SecondTestComponent.type is deprecated. Use ' +
69
'SecondTestComponent directly to access the class.'
70
);
71
// Not again
72
expect(TestComponent.type).toBe(TestComponent);
73
- expect(console.warn.argsForCall.length).toBe(2);
73
+ expect(console.error.argsForCall.length).toBe(2);
74
});
75
76
it('should copy prop types onto the Constructor', function() {
@@ -90,8 +90,8 @@ describe('ReactClass-spec', function() {
90
});
91
92
it('should warn on invalid prop types', function() {
93
- var warn = console.warn;
94
- console.warn = mocks.getMockFunction();
93
+ var warn = console.error;
94
+ console.error = mocks.getMockFunction();
95
try {
96
97
React.createClass({
@@ -103,19 +103,19 @@ describe('ReactClass-spec', function() {
103
return <span>{this.props.prop}</span>;
104
}
105
});
106
- expect(console.warn.mock.calls.length).toBe(1);
107
- expect(console.warn.mock.calls[0][0]).toBe(
106
+ expect(console.error.mock.calls.length).toBe(1);
107
+ expect(console.error.mock.calls[0][0]).toBe(
108
'Warning: Component: prop type `prop` is invalid; ' +
109
'it must be a function, usually from React.PropTypes.'
110
);
111
} finally {
112
- console.warn = warn;
112
+ console.error = warn;
113
}
114
});
115
116
it('should warn on invalid context types', function() {
117
- var warn = console.warn;
118
- console.warn = mocks.getMockFunction();
117
+ var warn = console.error;
118
+ console.error = mocks.getMockFunction();
119
try {
120
React.createClass({
121
displayName: 'Component',
@@ -126,19 +126,19 @@ describe('ReactClass-spec', function() {
126
return <span>{this.props.prop}</span>;
127
}
128
});
129
- expect(console.warn.mock.calls.length).toBe(1);
130
- expect(console.warn.mock.calls[0][0]).toBe(
129
+ expect(console.error.mock.calls.length).toBe(1);
130
+ expect(console.error.mock.calls[0][0]).toBe(
131
'Warning: Component: context type `prop` is invalid; ' +
132
'it must be a function, usually from React.PropTypes.'
133
);
134
} finally {
135
- console.warn = warn;
135
+ console.error = warn;
136
}
137
});
138
139
it('should throw on invalid child context types', function() {
140
- var warn = console.warn;
141
- console.warn = mocks.getMockFunction();
140
+ var warn = console.error;
141
+ console.error = mocks.getMockFunction();
142
try {
143
React.createClass({
144
displayName: 'Component',
@@ -149,13 +149,13 @@ describe('ReactClass-spec', function() {
149
return <span>{this.props.prop}</span>;
150
}
151
});
152
- expect(console.warn.mock.calls.length).toBe(1);
153
- expect(console.warn.mock.calls[0][0]).toBe(
152
+ expect(console.error.mock.calls.length).toBe(1);
153
+ expect(console.error.mock.calls[0][0]).toBe(
154
'Warning: Component: child context type `prop` is invalid; ' +
155
'it must be a function, usually from React.PropTypes.'
156
);
157
} finally {
158
- console.warn = warn;
158
+ console.error = warn;
159
}
160
});
161
@@ -168,8 +168,8 @@ describe('ReactClass-spec', function() {
168
return <div />;
169
}
170
});
171
- expect(console.warn.argsForCall.length).toBe(1);
172
- expect(console.warn.argsForCall[0][0]).toBe(
171
+ expect(console.error.argsForCall.length).toBe(1);
172
+ expect(console.error.argsForCall[0][0]).toBe(
173
'Warning: A component has a method called componentShouldUpdate(). Did you ' +
174
'mean shouldComponentUpdate()? The name is phrased as a question ' +
175
'because the function is expected to return a value.'
@@ -183,8 +183,8 @@ describe('ReactClass-spec', function() {
183
return <div />;
184
}
185
});
186
- expect(console.warn.argsForCall.length).toBe(2);
187
- expect(console.warn.argsForCall[1][0]).toBe(
186
+ expect(console.error.argsForCall.length).toBe(2);
187
+ expect(console.error.argsForCall[1][0]).toBe(
188
'Warning: NamedComponent has a method called componentShouldUpdate(). Did you ' +
189
'mean shouldComponentUpdate()? The name is phrased as a question ' +
190
'because the function is expected to return a value.'
@@ -234,20 +234,20 @@ describe('ReactClass-spec', function() {
234
return <div />;
235
}
236
});
237
- expect(console.warn.argsForCall.length).toBe(4);
238
- expect(console.warn.argsForCall[0][0]).toBe(
237
+ expect(console.error.argsForCall.length).toBe(4);
238
+ expect(console.error.argsForCall[0][0]).toBe(
239
'createClass(...): `mixins` is now a static property and should ' +
240
'be defined inside "statics".'
241
);
242
- expect(console.warn.argsForCall[1][0]).toBe(
242
+ expect(console.error.argsForCall[1][0]).toBe(
243
'createClass(...): `propTypes` is now a static property and should ' +
244
'be defined inside "statics".'
245
);
246
- expect(console.warn.argsForCall[2][0]).toBe(
246
+ expect(console.error.argsForCall[2][0]).toBe(
247
'createClass(...): `contextTypes` is now a static property and ' +
248
'should be defined inside "statics".'
249
);
250
- expect(console.warn.argsForCall[3][0]).toBe(
250
+ expect(console.error.argsForCall[3][0]).toBe(
251
'createClass(...): `childContextTypes` is now a static property and ' +
252
'should be defined inside "statics".'
253
);
@@ -371,8 +371,8 @@ describe('ReactClass-spec', function() {
371
});
372
373
expect(() => Component()).toThrow();
374
- expect(console.warn.calls.length).toBe(1);
375
- expect(console.warn.argsForCall[0][0]).toBe(
374
+ expect(console.error.calls.length).toBe(1);
375
+ expect(console.error.argsForCall[0][0]).toBe(
376
'Warning: Something is calling a React component directly. Use a ' +
377
'factory or JSX instead. See: http://fb.me/react-legacyfactory'
378
);
src/classic/element/__tests__/ReactElement-test.js
+26
-26
@@ -129,43 +129,43 @@ describe('ReactElement', function() {
129
});
130
131
it('merges an additional argument onto the children prop', function() {
132
- spyOn(console, 'warn');
132
+ spyOn(console, 'error');
133
var a = 1;
134
var element = React.createFactory(ComponentClass)({
135
children: 'text'
136
}, a);
137
expect(element.props.children).toBe(a);
138
- expect(console.warn.argsForCall.length).toBe(0);
138
+ expect(console.error.argsForCall.length).toBe(0);
139
});
140
141
it('does not override children if no rest args are provided', function() {
142
- spyOn(console, 'warn');
142
+ spyOn(console, 'error');
143
var element = React.createFactory(ComponentClass)({
144
children: 'text'
145
});
146
expect(element.props.children).toBe('text');
147
- expect(console.warn.argsForCall.length).toBe(0);
147
+ expect(console.error.argsForCall.length).toBe(0);
148
});
149
150
it('overrides children if null is provided as an argument', function() {
151
- spyOn(console, 'warn');
151
+ spyOn(console, 'error');
152
var element = React.createFactory(ComponentClass)({
153
children: 'text'
154
}, null);
155
expect(element.props.children).toBe(null);
156
- expect(console.warn.argsForCall.length).toBe(0);
156
+ expect(console.error.argsForCall.length).toBe(0);
157
});
158
159
it('merges rest arguments onto the children prop in an array', function() {
160
- spyOn(console, 'warn');
160
+ spyOn(console, 'error');
161
var a = 1, b = 2, c = 3;
162
var element = React.createFactory(ComponentClass)(null, a, b, c);
163
expect(element.props.children).toEqual([1, 2, 3]);
164
- expect(console.warn.argsForCall.length).toBe(0);
164
+ expect(console.error.argsForCall.length).toBe(0);
165
});
166
167
it('allows static methods to be called using the type property', function() {
168
- spyOn(console, 'warn');
168
+ spyOn(console, 'error');
169
170
var ComponentClass = React.createClass({
171
statics: {
@@ -183,7 +183,7 @@ describe('ReactElement', function() {
183
184
var element = React.createElement(ComponentClass);
185
expect(element.type.someStaticMethod()).toBe('someReturnValue');
186
- expect(console.warn.argsForCall.length).toBe(0);
186
+ expect(console.error.argsForCall.length).toBe(0);
187
});
188
189
it('identifies valid elements', function() {
@@ -270,7 +270,7 @@ describe('ReactElement', function() {
270
});
271
272
it('warns when changing a prop after element creation', function() {
273
- spyOn(console, 'warn');
273
+ spyOn(console, 'error');
274
var Outer = React.createClass({
275
render: function() {
276
var el = <div className="moo" />;
@@ -285,15 +285,15 @@ describe('ReactElement', function() {
285
var outer = ReactTestUtils.renderIntoDocument(<Outer color="orange" />);
286
expect(React.findDOMNode(outer).className).toBe('quack');
287
288
- expect(console.warn.argsForCall.length).toBe(1);
289
- expect(console.warn.argsForCall[0][0]).toContain(
288
+ expect(console.error.argsForCall.length).toBe(1);
289
+ expect(console.error.argsForCall[0][0]).toContain(
290
'Don\'t set .props.className of the React component <div />.'
291
);
292
- expect(console.warn.argsForCall[0][0]).toContain(
292
+ expect(console.error.argsForCall[0][0]).toContain(
293
'The element was created by Outer.'
294
);
295
296
- console.warn.reset();
296
+ console.error.reset();
297
298
// This also warns (just once per key/type pair)
299
outer.props.color = 'green';
@@ -301,14 +301,14 @@ describe('ReactElement', function() {
301
outer.props.color = 'purple';
302
outer.forceUpdate();
303
304
- expect(console.warn.argsForCall.length).toBe(1);
305
- expect(console.warn.argsForCall[0][0]).toContain(
304
+ expect(console.error.argsForCall.length).toBe(1);
305
+ expect(console.error.argsForCall[0][0]).toContain(
306
'Don\'t set .props.color of the React component <Outer />.'
307
);
308
});
309
310
it('warns when adding a prop after element creation', function() {
311
- spyOn(console, 'warn');
311
+ spyOn(console, 'error');
312
var el = document.createElement('div');
313
var Outer = React.createClass({
314
getDefaultProps: () => ({sound: 'meow'}),
@@ -327,15 +327,15 @@ describe('ReactElement', function() {
327
expect(React.findDOMNode(outer).textContent).toBe('meow');
328
expect(React.findDOMNode(outer).className).toBe('quack');
329
330
- expect(console.warn.argsForCall.length).toBe(1);
331
- expect(console.warn.argsForCall[0][0]).toContain(
330
+ expect(console.error.argsForCall.length).toBe(1);
331
+ expect(console.error.argsForCall[0][0]).toContain(
332
'Don\'t set .props.className of the React component <div />.'
333
);
334
- expect(console.warn.argsForCall[0][0]).toContain(
334
+ expect(console.error.argsForCall[0][0]).toContain(
335
'The element was created by Outer.'
336
);
337
338
- console.warn.reset();
338
+ console.error.reset();
339
340
var newOuterEl = <Outer />;
341
newOuterEl.props.sound = 'oink';
@@ -343,14 +343,14 @@ describe('ReactElement', function() {
343
expect(React.findDOMNode(outer).textContent).toBe('oink');
344
expect(React.findDOMNode(outer).className).toBe('quack');
345
346
- expect(console.warn.argsForCall.length).toBe(1);
347
- expect(console.warn.argsForCall[0][0]).toContain(
346
+ expect(console.error.argsForCall.length).toBe(1);
347
+ expect(console.error.argsForCall[0][0]).toContain(
348
'Don\'t set .props.sound of the React component <Outer />.'
349
);
350
});
351
352
it('does not warn for NaN props', function() {
353
- spyOn(console, 'warn');
353
+ spyOn(console, 'error');
354
var Test = React.createClass({
355
render: function() {
356
return <div />;
@@ -358,7 +358,7 @@ describe('ReactElement', function() {
358
});
359
var test = ReactTestUtils.renderIntoDocument(<Test value={+undefined} />);
360
expect(test.props.value).toBeNaN();
361
- expect(console.warn.argsForCall.length).toBe(0);
361
+ expect(console.error.argsForCall.length).toBe(0);
362
});
363
364
});
src/classic/element/__tests__/ReactElementClone-test.js
+12
-12
@@ -199,42 +199,42 @@ describe('ReactElementClone', function() {
199
});
200
201
it('warns for keys for arrays of elements in rest args', function() {
202
- spyOn(console, 'warn');
202
+ spyOn(console, 'error');
203
204
React.cloneElement(<div />, null, [<div />, <div />]);
205
206
- expect(console.warn.argsForCall.length).toBe(1);
207
- expect(console.warn.argsForCall[0][0]).toContain(
206
+ expect(console.error.argsForCall.length).toBe(1);
207
+ expect(console.error.argsForCall[0][0]).toContain(
208
'Each child in an array or iterator should have a unique "key" prop.'
209
);
210
});
211
212
it('does not warns for arrays of elements with keys', function() {
213
- spyOn(console, 'warn');
213
+ spyOn(console, 'error');
214
215
React.cloneElement(<div />, null, [<div key="#1" />, <div key="#2" />]);
216
217
- expect(console.warn.argsForCall.length).toBe(0);
217
+ expect(console.error.argsForCall.length).toBe(0);
218
});
219
220
it('does not warn when the element is directly in rest args', function() {
221
- spyOn(console, 'warn');
221
+ spyOn(console, 'error');
222
223
React.cloneElement(<div />, null, <div />, <div />);
224
225
- expect(console.warn.argsForCall.length).toBe(0);
225
+ expect(console.error.argsForCall.length).toBe(0);
226
});
227
228
it('does not warn when the array contains a non-element', function() {
229
- spyOn(console, 'warn');
229
+ spyOn(console, 'error');
230
231
React.cloneElement(<div />, null, [{}, {}]);
232
233
- expect(console.warn.argsForCall.length).toBe(0);
233
+ expect(console.error.argsForCall.length).toBe(0);
234
});
235
236
it('should check declared prop types after clone', function() {
237
- spyOn(console, 'warn');
237
+ spyOn(console, 'error');
238
var Component = React.createClass({
239
propTypes: {
240
color: React.PropTypes.string.isRequired
@@ -257,8 +257,8 @@ describe('ReactElementClone', function() {
257
}
258
});
259
ReactTestUtils.renderIntoDocument(React.createElement(GrandParent));
260
- expect(console.warn.argsForCall.length).toBe(1);
261
- expect(console.warn.calls[0].args[0]).toBe(
260
+ expect(console.error.argsForCall.length).toBe(1);
261
+ expect(console.error.calls[0].args[0]).toBe(
262
'Warning: Failed propType: ' +
263
'Invalid prop `color` of type `number` supplied to `Component`, ' +
264
'expected `string`. Check the render method of `Parent`.'
src/classic/element/__tests__/ReactElementValidator-test.js
+60
-60
@@ -37,19 +37,19 @@ describe('ReactElementValidator', function() {
37
}
38
39
it('warns for keys for arrays of elements in rest args', function() {
40
- spyOn(console, 'warn');
40
+ spyOn(console, 'error');
41
var Component = React.createFactory(ComponentClass);
42
43
Component(null, [Component(), Component()]);
44
45
- expect(console.warn.argsForCall.length).toBe(1);
46
- expect(console.warn.argsForCall[0][0]).toContain(
45
+ expect(console.error.argsForCall.length).toBe(1);
46
+ expect(console.error.argsForCall[0][0]).toContain(
47
'Each child in an array or iterator should have a unique "key" prop.'
48
);
49
});
50
51
it('warns for keys for arrays of elements with owner info', function() {
52
- spyOn(console, 'warn');
52
+ spyOn(console, 'error');
53
var Component = React.createFactory(ComponentClass);
54
55
var InnerClass = React.createClass({
@@ -72,8 +72,8 @@ describe('ReactElementValidator', function() {
72
React.createElement(ComponentWrapper)
73
);
74
75
- expect(console.warn.argsForCall.length).toBe(1);
76
- expect(console.warn.argsForCall[0][0]).toContain(
75
+ expect(console.error.argsForCall.length).toBe(1);
76
+ expect(console.error.argsForCall[0][0]).toContain(
77
'Each child in an array or iterator should have a unique "key" prop. ' +
78
'Check the render method of InnerClass. ' +
79
'It was passed a child from ComponentWrapper. '
@@ -81,7 +81,7 @@ describe('ReactElementValidator', function() {
81
});
82
83
it('warns for keys for arrays with no owner or parent info', function() {
84
- spyOn(console, 'warn');
84
+ spyOn(console, 'error');
85
86
var Anonymous = React.createClass({
87
displayName: undefined,
@@ -96,15 +96,15 @@ describe('ReactElementValidator', function() {
96
];
97
ReactTestUtils.renderIntoDocument(<Anonymous>{divs}</Anonymous>);
98
99
- expect(console.warn.argsForCall.length).toBe(1);
100
- expect(console.warn.argsForCall[0][0]).toBe(
99
+ expect(console.error.argsForCall.length).toBe(1);
100
+ expect(console.error.argsForCall[0][0]).toBe(
101
'Warning: Each child in an array or iterator should have a unique ' +
102
'"key" prop. See http://fb.me/react-warning-keys for more information.'
103
);
104
});
105
106
it('warns for keys for arrays of elements with no owner info', function() {
107
- spyOn(console, 'warn');
107
+ spyOn(console, 'error');
108
109
var divs = [
110
<div />,
@@ -112,8 +112,8 @@ describe('ReactElementValidator', function() {
112
];
113
ReactTestUtils.renderIntoDocument(<div>{divs}</div>);
114
115
- expect(console.warn.argsForCall.length).toBe(1);
116
- expect(console.warn.argsForCall[0][0]).toBe(
115
+ expect(console.error.argsForCall.length).toBe(1);
116
+ expect(console.error.argsForCall[0][0]).toBe(
117
'Warning: Each child in an array or iterator should have a unique ' +
118
'"key" prop. Check the React.render call using <div>. See ' +
119
'http://fb.me/react-warning-keys for more information.'
@@ -121,7 +121,7 @@ describe('ReactElementValidator', function() {
121
});
122
123
it('warns for keys for iterables of elements in rest args', function() {
124
- spyOn(console, 'warn');
124
+ spyOn(console, 'error');
125
var Component = React.createFactory(ComponentClass);
126
127
var iterable = {
@@ -138,23 +138,23 @@ describe('ReactElementValidator', function() {
138
139
Component(null, iterable);
140
141
- expect(console.warn.argsForCall.length).toBe(1);
142
- expect(console.warn.argsForCall[0][0]).toContain(
141
+ expect(console.error.argsForCall.length).toBe(1);
142
+ expect(console.error.argsForCall[0][0]).toContain(
143
'Each child in an array or iterator should have a unique "key" prop.'
144
);
145
});
146
147
it('does not warns for arrays of elements with keys', function() {
148
- spyOn(console, 'warn');
148
+ spyOn(console, 'error');
149
var Component = React.createFactory(ComponentClass);
150
151
Component(null, [Component({key: '#1'}), Component({key: '#2'})]);
152
153
- expect(console.warn.argsForCall.length).toBe(0);
153
+ expect(console.error.argsForCall.length).toBe(0);
154
});
155
156
it('does not warns for iterable elements with keys', function() {
157
- spyOn(console, 'warn');
157
+ spyOn(console, 'error');
158
var Component = React.createFactory(ComponentClass);
159
160
var iterable = {
@@ -174,23 +174,23 @@ describe('ReactElementValidator', function() {
174
175
Component(null, iterable);
176
177
- expect(console.warn.argsForCall.length).toBe(0);
177
+ expect(console.error.argsForCall.length).toBe(0);
178
});
179
180
it('warns for numeric keys on objects in rest args', function() {
181
- spyOn(console, 'warn');
181
+ spyOn(console, 'error');
182
var Component = React.createFactory(ComponentClass);
183
184
Component(null, frag({1: Component(), 2: Component()}));
185
186
- expect(console.warn.argsForCall.length).toBe(1);
187
- expect(console.warn.argsForCall[0][0]).toContain(
186
+ expect(console.error.argsForCall.length).toBe(1);
187
+ expect(console.error.argsForCall[0][0]).toContain(
188
'Child objects should have non-numeric keys so ordering is preserved.'
189
);
190
});
191
192
it('does not warn for numeric keys in entry iterables in rest args', function() {
193
- spyOn(console, 'warn');
193
+ spyOn(console, 'error');
194
var Component = React.createFactory(ComponentClass);
195
196
var iterable = {
@@ -208,25 +208,25 @@ describe('ReactElementValidator', function() {
208
209
Component(null, iterable);
210
211
- expect(console.warn.argsForCall.length).toBe(0);
211
+ expect(console.error.argsForCall.length).toBe(0);
212
});
213
214
it('does not warn when the element is directly in rest args', function() {
215
- spyOn(console, 'warn');
215
+ spyOn(console, 'error');
216
var Component = React.createFactory(ComponentClass);
217
218
Component(null, Component(), Component());
219
220
- expect(console.warn.argsForCall.length).toBe(0);
220
+ expect(console.error.argsForCall.length).toBe(0);
221
});
222
223
it('does not warn when the array contains a non-element', function() {
224
- spyOn(console, 'warn');
224
+ spyOn(console, 'error');
225
var Component = React.createFactory(ComponentClass);
226
227
Component(null, [ {}, {} ]);
228
229
- expect(console.warn.argsForCall.length).toBe(0);
229
+ expect(console.error.argsForCall.length).toBe(0);
230
});
231
232
// TODO: These warnings currently come from the composite component, but
@@ -236,7 +236,7 @@ describe('ReactElementValidator', function() {
236
// In this test, we're making sure that if a proptype error is found in a
237
// component, we give a small hint as to which parent instantiated that
238
// component as per warnings about key usage in ReactElementValidator.
239
- spyOn(console, 'warn');
239
+ spyOn(console, 'error');
240
var MyComp = React.createClass({
241
propTypes: {
242
color: React.PropTypes.string
@@ -251,7 +251,7 @@ describe('ReactElementValidator', function() {
251
}
252
});
253
ReactTestUtils.renderIntoDocument(React.createElement(ParentComp));
254
- expect(console.warn.calls[0].args[0]).toBe(
254
+ expect(console.error.calls[0].args[0]).toBe(
255
'Warning: Failed propType: ' +
256
'Invalid prop `color` of type `number` supplied to `MyComp`, ' +
257
'expected `string`. Check the render method of `ParentComp`.'
@@ -259,26 +259,26 @@ describe('ReactElementValidator', function() {
259
});
260
261
it('gives a helpful error when passing null or undefined', function() {
262
- spyOn(console, 'warn');
262
+ spyOn(console, 'error');
263
React.createElement(undefined);
264
React.createElement(null);
265
- expect(console.warn.calls.length).toBe(2);
266
- expect(console.warn.calls[0].args[0]).toBe(
265
+ expect(console.error.calls.length).toBe(2);
266
+ expect(console.error.calls[0].args[0]).toBe(
267
'Warning: React.createElement: type should not be null or undefined. ' +
268
'It should be a string (for DOM elements) or a ReactClass (for ' +
269
'composite components).'
270
);
271
- expect(console.warn.calls[1].args[0]).toBe(
271
+ expect(console.error.calls[1].args[0]).toBe(
272
'Warning: React.createElement: type should not be null or undefined. ' +
273
'It should be a string (for DOM elements) or a ReactClass (for ' +
274
'composite components).'
275
);
276
React.createElement('div');
277
- expect(console.warn.calls.length).toBe(2);
277
+ expect(console.error.calls.length).toBe(2);
278
});
279
280
it('includes the owner name when passing null or undefined', function() {
281
- spyOn(console, 'warn');
281
+ spyOn(console, 'error');
282
var ParentComp = React.createClass({
283
render: function() {
284
return React.createElement(null);
@@ -287,19 +287,19 @@ describe('ReactElementValidator', function() {
287
expect(function() {
288
ReactTestUtils.renderIntoDocument(React.createElement(ParentComp));
289
}).toThrow();
290
- expect(console.warn.calls.length).toBe(2);
291
- expect(console.warn.calls[0].args[0]).toBe(
290
+ expect(console.error.calls.length).toBe(2);
291
+ expect(console.error.calls[0].args[0]).toBe(
292
'Warning: React.createElement: type should not be null or undefined. ' +
293
'It should be a string (for DOM elements) or a ReactClass (for ' +
294
'composite components). Check the render method of `ParentComp`.'
295
);
296
- expect(console.warn.calls[1].args[0]).toBe(
296
+ expect(console.error.calls[1].args[0]).toBe(
297
'Warning: Only functions or strings can be mounted as React components.'
298
);
299
});
300
301
it('should check default prop values', function() {
302
- spyOn(console, 'warn');
302
+ spyOn(console, 'error');
303
304
var Component = React.createClass({
305
propTypes: {prop: React.PropTypes.string.isRequired},
@@ -313,15 +313,15 @@ describe('ReactElementValidator', function() {
313
314
ReactTestUtils.renderIntoDocument(React.createElement(Component));
315
316
- expect(console.warn.calls.length).toBe(1);
317
- expect(console.warn.calls[0].args[0]).toBe(
316
+ expect(console.error.calls.length).toBe(1);
317
+ expect(console.error.calls[0].args[0]).toBe(
318
'Warning: Failed propType: ' +
319
'Required prop `prop` was not specified in `Component`.'
320
);
321
});
322
323
it('should not check the default for explicit null', function() {
324
- spyOn(console, 'warn');
324
+ spyOn(console, 'error');
325
326
var Component = React.createClass({
327
propTypes: {prop: React.PropTypes.string.isRequired},
@@ -337,15 +337,15 @@ describe('ReactElementValidator', function() {
337
React.createElement(Component, {prop:null})
338
);
339
340
- expect(console.warn.calls.length).toBe(1);
341
- expect(console.warn.calls[0].args[0]).toBe(
340
+ expect(console.error.calls.length).toBe(1);
341
+ expect(console.error.calls[0].args[0]).toBe(
342
'Warning: Failed propType: ' +
343
'Required prop `prop` was not specified in `Component`.'
344
);
345
});
346
347
it('should check declared prop types', function() {
348
- spyOn(console, 'warn');
348
+ spyOn(console, 'error');
349
350
var Component = React.createClass({
351
propTypes: {
@@ -363,13 +363,13 @@ describe('ReactElementValidator', function() {
363
React.createElement(Component, {prop: 42})
364
);
365
366
- expect(console.warn.calls.length).toBe(2);
367
- expect(console.warn.calls[0].args[0]).toBe(
366
+ expect(console.error.calls.length).toBe(2);
367
+ expect(console.error.calls[0].args[0]).toBe(
368
'Warning: Failed propType: ' +
369
'Required prop `prop` was not specified in `Component`.'
370
);
371
372
- expect(console.warn.calls[1].args[0]).toBe(
372
+ expect(console.error.calls[1].args[0]).toBe(
373
'Warning: Failed propType: ' +
374
'Invalid prop `prop` of type `number` supplied to ' +
375
'`Component`, expected `string`.'
@@ -380,11 +380,11 @@ describe('ReactElementValidator', function() {
380
);
381
382
// Should not error for strings
383
- expect(console.warn.calls.length).toBe(2);
383
+ expect(console.error.calls.length).toBe(2);
384
});
385
386
it('should warn if a PropType creator is used as a PropType', function() {
387
- spyOn(console, 'warn');
387
+ spyOn(console, 'error');
388
389
var Component = React.createClass({
390
propTypes: {
@@ -399,8 +399,8 @@ describe('ReactElementValidator', function() {
399
React.createElement(Component, {myProp: {value: 'hi'}})
400
);
401
402
- expect(console.warn.calls.length).toBe(1);
403
- expect(console.warn.calls[0].args[0]).toBe(
402
+ expect(console.error.calls.length).toBe(1);
403
+ expect(console.error.calls[0].args[0]).toBe(
404
'Warning: Component: type specification of prop `myProp` is invalid; ' +
405
'the type checker function must return `null` or an `Error` but ' +
406
'returned a function. You may have forgotten to pass an argument to ' +
@@ -410,15 +410,15 @@ describe('ReactElementValidator', function() {
410
});
411
412
it('should warn if a fragment is used without the wrapper', function() {
413
- spyOn(console, 'warn');
413
+ spyOn(console, 'error');
414
var child = React.createElement('span');
415
React.createElement('div', null, {a: child, b: child});
416
- expect(console.warn.calls.length).toBe(1);
417
- expect(console.warn.calls[0].args[0]).toContain('use of a keyed object');
416
+ expect(console.error.calls.length).toBe(1);
417
+ expect(console.error.calls[0].args[0]).toContain('use of a keyed object');
418
});
419
420
it('should warn when accessing .type on an element factory', function() {
421
- spyOn(console, 'warn');
421
+ spyOn(console, 'error');
422
var TestComponent = React.createClass({
423
render: function() {
424
return <div />;
@@ -426,14 +426,14 @@ describe('ReactElementValidator', function() {
426
});
427
var TestFactory = React.createFactory(TestComponent);
428
expect(TestFactory.type).toBe(TestComponent);
429
- expect(console.warn.argsForCall.length).toBe(1);
430
- expect(console.warn.argsForCall[0][0]).toBe(
429
+ expect(console.error.argsForCall.length).toBe(1);
430
+ expect(console.error.argsForCall[0][0]).toBe(
431
'Warning: Factory.type is deprecated. Access the class directly before ' +
432
'passing it to createFactory.'
433
);
434
// Warn once, not again
435
expect(TestFactory.type).toBe(TestComponent);
436
- expect(console.warn.argsForCall.length).toBe(1);
436
+ expect(console.error.argsForCall.length).toBe(1);
437
});
438
439
});
src/classic/types/__tests__/ReactPropTypes-test.js
+9
-9
@@ -233,7 +233,7 @@ describe('ReactPropTypes', function() {
233
return <div>{this.props.label}</div>;
234
}
235
});
236
- spyOn(console, 'warn');
236
+ spyOn(console, 'error');
237
});
238
239
it('should support components', () => {
@@ -253,14 +253,14 @@ describe('ReactPropTypes', function() {
253
var instance = <Component label={<div />} />;
254
instance = ReactTestUtils.renderIntoDocument(instance);
255
256
- expect(console.warn.argsForCall.length).toBe(0);
256
+ expect(console.error.argsForCall.length).toBe(0);
257
});
258
259
it('should warn when passing no label and isRequired is set', () => {
260
var instance = <Component />;
261
instance = ReactTestUtils.renderIntoDocument(instance);
262
263
- expect(console.warn.argsForCall.length).toBe(1);
263
+ expect(console.error.argsForCall.length).toBe(1);
264
});
265
266
it("should be implicitly optional and not warn without values", function() {
@@ -358,7 +358,7 @@ describe('ReactPropTypes', function() {
358
});
359
360
it('should not warn for valid values', function() {
361
- spyOn(console, 'warn');
361
+ spyOn(console, 'error');
362
typeCheckPass(PropTypes.node, <div />);
363
typeCheckPass(PropTypes.node, false);
364
typeCheckPass(PropTypes.node, <MyComponent />);
@@ -388,7 +388,7 @@ describe('ReactPropTypes', function() {
388
k4: null,
389
k5: undefined
390
}));
391
- expect(console.warn.calls).toEqual([]);
391
+ expect(console.error.calls).toEqual([]);
392
393
// This should also pass, though it warns
394
typeCheckPass(PropTypes.node, {
@@ -717,7 +717,7 @@ describe('ReactPropTypes', function() {
717
describe('Custom validator', function() {
718
beforeEach(function() {
719
require('mock-modules').dumpCache();
720
- spyOn(console, 'warn');
720
+ spyOn(console, 'error');
721
});
722
723
it('should have been called with the right params', function() {
@@ -772,8 +772,8 @@ describe('ReactPropTypes', function() {
772
773
var instance = <Component num={6} />;
774
instance = ReactTestUtils.renderIntoDocument(instance);
775
- expect(console.warn.argsForCall.length).toBe(1);
776
- expect(console.warn.argsForCall[0][0]).toBe(
775
+ expect(console.error.argsForCall.length).toBe(1);
776
+ expect(console.error.argsForCall[0][0]).toBe(
777
'Warning: Failed propType: num must be 5!');
778
});
779
@@ -794,7 +794,7 @@ describe('ReactPropTypes', function() {
794
795
var instance = <Component num={5} />;
796
instance = ReactTestUtils.renderIntoDocument(instance);
797
- expect(console.warn.argsForCall.length).toBe(0);
797
+ expect(console.error.argsForCall.length).toBe(0);
798
}
799
);
800
});
src/core/__tests__/ReactComponentLifeCycle-test.js
+9
-9
@@ -239,7 +239,7 @@ describe('ReactComponentLifeCycle', function() {
239
});
240
241
it('should not allow update state inside of getInitialState', function() {
242
- spyOn(console, 'warn');
242
+ spyOn(console, 'error');
243
var StatefulComponent = React.createClass({
244
getInitialState: function() {
245
this.setState({stateField: 'something'});
@@ -253,8 +253,8 @@ describe('ReactComponentLifeCycle', function() {
253
}
254
});
255
ReactTestUtils.renderIntoDocument(<StatefulComponent />);
256
- expect(console.warn.calls.length).toBe(1);
257
- expect(console.warn.argsForCall[0][0]).toBe(
256
+ expect(console.error.calls.length).toBe(1);
257
+ expect(console.error.argsForCall[0][0]).toBe(
258
'Warning: setState(...): Can only update a mounted or ' +
259
'mounting component. This usually means you called setState() on an ' +
260
'unmounted component. This is a no-op.'
@@ -262,7 +262,7 @@ describe('ReactComponentLifeCycle', function() {
262
});
263
264
it('should correctly determine if a component is mounted', function() {
265
- spyOn(console, 'warn');
265
+ spyOn(console, 'error');
266
var Component = React.createClass({
267
componentWillMount: function() {
268
expect(this.isMounted()).toBeFalsy();
@@ -281,14 +281,14 @@ describe('ReactComponentLifeCycle', function() {
281
var instance = ReactTestUtils.renderIntoDocument(element);
282
expect(instance.isMounted()).toBeTruthy();
283
284
- expect(console.warn.argsForCall.length).toBe(1);
285
- expect(console.warn.argsForCall[0][0]).toContain(
284
+ expect(console.error.argsForCall.length).toBe(1);
285
+ expect(console.error.argsForCall[0][0]).toContain(
286
'Component is accessing isMounted inside its render()'
287
);
288
});
289
290
it('warns if findDOMNode is used inside render', function() {
291
- spyOn(console, 'warn');
291
+ spyOn(console, 'error');
292
var Component = React.createClass({
293
getInitialState: function() {
294
return {isMounted: false};
@@ -305,8 +305,8 @@ describe('ReactComponentLifeCycle', function() {
305
});
306
307
ReactTestUtils.renderIntoDocument(<Component />);
308
- expect(console.warn.argsForCall.length).toBe(1);
309
- expect(console.warn.argsForCall[0][0]).toContain(
308
+ expect(console.error.argsForCall.length).toBe(1);
309
+ expect(console.error.argsForCall[0][0]).toContain(
310
'Component is accessing getDOMNode or findDOMNode inside its render()'
311
);
312
});
src/core/__tests__/ReactCompositeComponent-test.js
+31
-31
@@ -74,10 +74,10 @@ describe('ReactCompositeComponent', function() {
74
// Ignore the first warning which is fired by using withContext at all.
75
// That way we don't have to reset and assert it on every subsequent test.
76
// This will be killed soon anyway.
77
- console.warn = mocks.getMockFunction();
77
+ console.error = mocks.getMockFunction();
78
React.withContext({}, function() { });
79
80
- spyOn(console, 'warn');
80
+ spyOn(console, 'error');
81
});
82
83
it('should support rendering to different child types over time', function() {
@@ -116,7 +116,7 @@ describe('ReactCompositeComponent', function() {
116
container.innerHTML = markup;
117
118
React.render(<Parent />, container);
119
- expect(console.warn).not.toHaveBeenCalled();
119
+ expect(console.error).not.toHaveBeenCalled();
120
});
121
122
it('should react to state changes from callbacks', function() {
@@ -191,11 +191,11 @@ describe('ReactCompositeComponent', function() {
191
mountedInstance.methodExplicitlyNotBound();
192
}).not.toThrow();
193
194
- expect(console.warn.argsForCall.length).toBe(1);
194
+ expect(console.error.argsForCall.length).toBe(1);
195
var explicitlyBound = mountedInstance.methodToBeExplicitlyBound.bind(
196
mountedInstance
197
);
198
- expect(console.warn.argsForCall.length).toBe(2);
198
+ expect(console.error.argsForCall.length).toBe(2);
199
var autoBound = mountedInstance.methodAutoBound;
200
var explicitlyNotBound = mountedInstance.methodExplicitlyNotBound;
201
@@ -283,13 +283,13 @@ describe('ReactCompositeComponent', function() {
283
instance = React.render(instance, container);
284
instance.forceUpdate();
285
286
- expect(console.warn.calls.length).toBe(0);
286
+ expect(console.error.calls.length).toBe(0);
287
288
React.unmountComponentAtNode(container);
289
290
instance.forceUpdate();
291
- expect(console.warn.calls.length).toBe(1);
292
- expect(console.warn.argsForCall[0][0]).toBe(
291
+ expect(console.error.calls.length).toBe(1);
292
+ expect(console.error.argsForCall[0][0]).toBe(
293
'Warning: forceUpdate(...): Can only update a mounted or ' +
294
'mounting component. This usually means you called forceUpdate() on ' +
295
'an unmounted component. This is a no-op.'
@@ -315,12 +315,12 @@ describe('ReactCompositeComponent', function() {
315
instance = React.render(instance, container);
316
instance.setState({value: 1});
317
318
- expect(console.warn.calls.length).toBe(0);
318
+ expect(console.error.calls.length).toBe(0);
319
320
React.unmountComponentAtNode(container);
321
instance.setState({value: 2});
322
- expect(console.warn.calls.length).toBe(1);
323
- expect(console.warn.argsForCall[0][0]).toBe(
322
+ expect(console.error.calls.length).toBe(1);
323
+ expect(console.error.argsForCall[0][0]).toBe(
324
'Warning: setState(...): Can only update a mounted or ' +
325
'mounting component. This usually means you called setState() on an ' +
326
'unmounted component. This is a no-op.'
@@ -352,10 +352,10 @@ describe('ReactCompositeComponent', function() {
352
var instance = React.render(<Component />, container);
353
354
instance.setState({value: 1});
355
- expect(console.warn.calls.length).toBe(0);
355
+ expect(console.error.calls.length).toBe(0);
356
357
React.unmountComponentAtNode(container);
358
- expect(console.warn.calls.length).toBe(0);
358
+ expect(console.error.calls.length).toBe(0);
359
expect(cbCalled).toBe(false);
360
});
361
@@ -376,15 +376,15 @@ describe('ReactCompositeComponent', function() {
376
expect(function() {
377
instance.setProps({value: 1});
378
}).not.toThrow();
379
- expect(console.warn.calls.length).toBe(0);
379
+ expect(console.error.calls.length).toBe(0);
380
381
React.unmountComponentAtNode(container);
382
expect(function() {
383
instance.setProps({value: 2});
384
}).not.toThrow();
385
386
- expect(console.warn.calls.length).toBe(1);
387
- expect(console.warn.argsForCall[0][0]).toBe(
386
+ expect(console.error.calls.length).toBe(1);
387
+ expect(console.error.argsForCall[0][0]).toBe(
388
'Warning: setProps(...): Can only update a mounted or ' +
389
'mounting component. This usually means you called setProps() on an ' +
390
'unmounted component. This is a no-op.'
@@ -493,8 +493,8 @@ describe('ReactCompositeComponent', function() {
493
var instance = ReactTestUtils.renderIntoDocument(<Component />);
494
instance.setState({bogus: true});
495
496
- expect(console.warn.argsForCall.length).toBe(1);
497
- expect(console.warn.argsForCall[0][0]).toBe(
496
+ expect(console.error.argsForCall.length).toBe(1);
497
+ expect(console.error.argsForCall[0][0]).toBe(
498
'Warning: Component.shouldComponentUpdate(): Returned undefined instead of a ' +
499
'boolean value. Make sure to return true or false.'
500
);
@@ -576,8 +576,8 @@ describe('ReactCompositeComponent', function() {
576
ReactTestUtils.renderIntoDocument(<Component />);
577
});
578
579
- expect(console.warn.argsForCall.length).toBe(1);
580
- expect(console.warn.argsForCall[0][0]).toBe(
579
+ expect(console.error.argsForCall.length).toBe(1);
580
+ expect(console.error.argsForCall[0][0]).toBe(
581
'Warning: owner-based and parent-based contexts differ ' +
582
'(values: `bar` vs `undefined`) for key (foo) ' +
583
'while mounting Component (see: http://fb.me/react-context-by-parent)'
@@ -619,8 +619,8 @@ describe('ReactCompositeComponent', function() {
619
620
// Two warnings, one for the component and one for the div
621
// We may want to make this expect one warning in the future
622
- expect(console.warn.argsForCall.length).toBe(1);
623
- expect(console.warn.argsForCall[0][0]).toBe(
622
+ expect(console.error.argsForCall.length).toBe(1);
623
+ expect(console.error.argsForCall[0][0]).toBe(
624
'Warning: owner-based and parent-based contexts differ ' +
625
'(values: `noise` vs `bar`) for key (foo) while mounting Component ' +
626
'(see: http://fb.me/react-context-by-parent)'
@@ -662,7 +662,7 @@ describe('ReactCompositeComponent', function() {
662
});
663
React.render(<Parent>{componentWithSameContext}</Parent>, div);
664
665
- expect(console.warn.argsForCall.length).toBe(0);
665
+ expect(console.error.argsForCall.length).toBe(0);
666
667
var componentWithDifferentContext = React.withContext({foo: 'noise'}, function() {
668
return <Component />;
@@ -671,8 +671,8 @@ describe('ReactCompositeComponent', function() {
671
672
// Two warnings, one for the component and one for the div
673
// We may want to make this expect one warning in the future
674
- expect(console.warn.argsForCall.length).toBe(1);
675
- expect(console.warn.argsForCall[0][0]).toBe(
674
+ expect(console.error.argsForCall.length).toBe(1);
675
+ expect(console.error.argsForCall[0][0]).toBe(
676
'Warning: owner-based and parent-based contexts differ ' +
677
'(values: `noise` vs `bar`) for key (foo) while mounting Component ' +
678
'(see: http://fb.me/react-context-by-parent)'
@@ -725,8 +725,8 @@ describe('ReactCompositeComponent', function() {
725
726
// Two warnings, one for the component and one for the div
727
// We may want to make this expect one warning in the future
728
- expect(console.warn.argsForCall.length).toBe(1);
729
- expect(console.warn.argsForCall[0][0]).toBe(
728
+ expect(console.error.argsForCall.length).toBe(1);
729
+ expect(console.error.argsForCall[0][0]).toBe(
730
'Warning: owner-based and parent-based contexts differ ' +
731
'(values: `noise` vs `bar`) for key (foo) while mounting Component ' +
732
'(see: http://fb.me/react-context-by-parent)'
@@ -820,8 +820,8 @@ describe('ReactCompositeComponent', function() {
820
});
821
822
ReactTestUtils.renderIntoDocument(<Outer />);
823
- expect(console.warn.argsForCall.length).toBe(1);
824
- expect(console.warn.argsForCall[0][0]).toBe(
823
+ expect(console.error.argsForCall.length).toBe(1);
824
+ expect(console.error.argsForCall[0][0]).toBe(
825
'Warning: _renderNewRootComponent(): Render methods should ' +
826
'be a pure function of props and state; triggering nested component ' +
827
'updates from render is not allowed. If necessary, trigger nested ' +
@@ -930,8 +930,8 @@ describe('ReactCompositeComponent', function() {
930
expect(function() {
931
ReactTestUtils.renderIntoDocument(<div><NotAComponent /></div>);
932
}).toThrow(); // has no method 'render'
933
- expect(console.warn.calls.length).toBe(1);
934
- expect(console.warn.calls[0].args[0]).toContain(
933
+ expect(console.error.calls.length).toBe(1);
934
+ expect(console.error.calls[0].args[0]).toContain(
935
'NotAComponent(...): No `render` method found'
936
);
937
});
src/core/__tests__/ReactMockedComponent-test.js
+2
-2
@@ -56,9 +56,9 @@ describe('ReactMockedComponent', function() {
56
});
57
58
it('should allow an implicitly mocked component to be rendered without warnings', () => {
59
- spyOn(console, 'warn');
59
+ spyOn(console, 'error');
60
ReactTestUtils.renderIntoDocument(<AutoMockedComponent />);
61
- expect(console.warn.calls.length).toBe(0);
61
+ expect(console.error.calls.length).toBe(0);
62
});
63
64
it('should allow an implicitly mocked component to be updated', () => {
src/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee
+15
-15
@@ -264,7 +264,7 @@ describe 'ReactCoffeeScriptClass', ->
264
265
it 'warns when classic properties are defined on the instance,
266
but does not invoke them.', ->
267
- spyOn console, 'warn'
267
+ spyOn console, 'error'
268
getInitialStateWasCalled = false
269
class Foo extends React.Component
270
constructor: ->
@@ -281,19 +281,19 @@ describe 'ReactCoffeeScriptClass', ->
281
282
test React.createElement(Foo), 'SPAN', 'foo'
283
expect(getInitialStateWasCalled).toBe false
284
- expect(console.warn.calls.length).toBe 3
285
- expect(console.warn.calls[0].args[0]).toContain(
284
+ expect(console.error.calls.length).toBe 3
285
+ expect(console.error.calls[0].args[0]).toContain(
286
'getInitialState was defined on Foo, a plain JavaScript class.'
287
)
288
- expect(console.warn.calls[1].args[0]).toContain(
288
+ expect(console.error.calls[1].args[0]).toContain(
289
'propTypes was defined as an instance property on Foo.'
290
)
291
- expect(console.warn.calls[2].args[0]).toContain(
291
+ expect(console.error.calls[2].args[0]).toContain(
292
'contextTypes was defined as an instance property on Foo.'
293
)
294
295
it 'should warn when mispelling shouldComponentUpdate', ->
296
- spyOn console, 'warn'
296
+ spyOn console, 'error'
297
class NamedComponent
298
componentShouldUpdate: ->
299
false
@@ -303,15 +303,15 @@ describe 'ReactCoffeeScriptClass', ->
303
className: 'foo'
304
305
test React.createElement(NamedComponent), 'SPAN', 'foo'
306
- expect(console.warn.calls.length).toBe 1
307
- expect(console.warn.calls[0].args[0]).toBe(
306
+ expect(console.error.calls.length).toBe 1
307
+ expect(console.error.calls[0].args[0]).toBe(
308
'Warning: NamedComponent has a method called componentShouldUpdate().
309
Did you mean shouldComponentUpdate()? The name is phrased as a
310
question because the function is expected to return a value.'
311
)
312
313
it 'should throw AND warn when trying to access classic APIs', ->
314
- spyOn console, 'warn'
314
+ spyOn console, 'error'
315
instance =
316
test Inner(name: 'foo'), 'DIV', 'foo'
317
expect(-> instance.getDOMNode()).toThrow()
@@ -319,20 +319,20 @@ describe 'ReactCoffeeScriptClass', ->
319
expect(-> instance.isMounted()).toThrow()
320
expect(-> instance.setProps name: 'bar').toThrow()
321
expect(-> instance.replaceProps name: 'bar').toThrow()
322
- expect(console.warn.calls.length).toBe 5
323
- expect(console.warn.calls[0].args[0]).toContain(
322
+ expect(console.error.calls.length).toBe 5
323
+ expect(console.error.calls[0].args[0]).toContain(
324
'getDOMNode(...) is deprecated in plain JavaScript React classes'
325
)
326
- expect(console.warn.calls[1].args[0]).toContain(
326
+ expect(console.error.calls[1].args[0]).toContain(
327
'replaceState(...) is deprecated in plain JavaScript React classes'
328
)
329
- expect(console.warn.calls[2].args[0]).toContain(
329
+ expect(console.error.calls[2].args[0]).toContain(
330
'isMounted(...) is deprecated in plain JavaScript React classes'
331
)
332
- expect(console.warn.calls[3].args[0]).toContain(
332
+ expect(console.error.calls[3].args[0]).toContain(
333
'setProps(...) is deprecated in plain JavaScript React classes'
334
)
335
- expect(console.warn.calls[4].args[0]).toContain(
335
+ expect(console.error.calls[4].args[0]).toContain(
336
'replaceProps(...) is deprecated in plain JavaScript React classes'
337
)
338
src/modern/class/__tests__/ReactES6Class-test.js
+15
-15
@@ -296,7 +296,7 @@ describe('ReactES6Class', function() {
296
297
it('warns when classic properties are defined on the instance, ' +
298
'but does not invoke them.', function() {
299
- spyOn(console, 'warn');
299
+ spyOn(console, 'error');
300
var getInitialStateWasCalled = false;
301
class Foo extends React.Component {
302
constructor() {
@@ -313,20 +313,20 @@ describe('ReactES6Class', function() {
313
}
314
test(<Foo />, 'SPAN', 'foo');
315
expect(getInitialStateWasCalled).toBe(false);
316
- expect(console.warn.calls.length).toBe(3);
317
- expect(console.warn.calls[0].args[0]).toContain(
316
+ expect(console.error.calls.length).toBe(3);
317
+ expect(console.error.calls[0].args[0]).toContain(
318
'getInitialState was defined on Foo, a plain JavaScript class.'
319
);
320
- expect(console.warn.calls[1].args[0]).toContain(
320
+ expect(console.error.calls[1].args[0]).toContain(
321
'propTypes was defined as an instance property on Foo.'
322
);
323
- expect(console.warn.calls[2].args[0]).toContain(
323
+ expect(console.error.calls[2].args[0]).toContain(
324
'contextTypes was defined as an instance property on Foo.'
325
);
326
});
327
328
it('should warn when mispelling shouldComponentUpdate', function() {
329
- spyOn(console, 'warn');
329
+ spyOn(console, 'error');
330
331
class NamedComponent {
332
componentShouldUpdate() {
@@ -338,8 +338,8 @@ describe('ReactES6Class', function() {
338
}
339
test(<NamedComponent />, 'SPAN', 'foo');
340
341
- expect(console.warn.calls.length).toBe(1);
342
- expect(console.warn.calls[0].args[0]).toBe(
341
+ expect(console.error.calls.length).toBe(1);
342
+ expect(console.error.calls[0].args[0]).toBe(
343
'Warning: ' +
344
'NamedComponent has a method called componentShouldUpdate(). Did you ' +
345
'mean shouldComponentUpdate()? The name is phrased as a question ' +
@@ -348,27 +348,27 @@ describe('ReactES6Class', function() {
348
});
349
350
it('should throw AND warn when trying to access classic APIs', function() {
351
- spyOn(console, 'warn');
351
+ spyOn(console, 'error');
352
var instance = test(<Inner name="foo" />, 'DIV', 'foo');
353
expect(() => instance.getDOMNode()).toThrow();
354
expect(() => instance.replaceState({})).toThrow();
355
expect(() => instance.isMounted()).toThrow();
356
expect(() => instance.setProps({name: 'bar'})).toThrow();
357
expect(() => instance.replaceProps({name: 'bar'})).toThrow();
358
- expect(console.warn.calls.length).toBe(5);
359
- expect(console.warn.calls[0].args[0]).toContain(
358
+ expect(console.error.calls.length).toBe(5);
359
+ expect(console.error.calls[0].args[0]).toContain(
360
'getDOMNode(...) is deprecated in plain JavaScript React classes'
361
);
362
- expect(console.warn.calls[1].args[0]).toContain(
362
+ expect(console.error.calls[1].args[0]).toContain(
363
'replaceState(...) is deprecated in plain JavaScript React classes'
364
);
365
- expect(console.warn.calls[2].args[0]).toContain(
365
+ expect(console.error.calls[2].args[0]).toContain(
366
'isMounted(...) is deprecated in plain JavaScript React classes'
367
);
368
- expect(console.warn.calls[3].args[0]).toContain(
368
+ expect(console.error.calls[3].args[0]).toContain(
369
'setProps(...) is deprecated in plain JavaScript React classes'
370
);
371
- expect(console.warn.calls[4].args[0]).toContain(
371
+ expect(console.error.calls[4].args[0]).toContain(
372
'replaceProps(...) is deprecated in plain JavaScript React classes'
373
);
374
});
src/modern/class/__tests__/ReactTypeScriptClass-test.ts
+3
-3
@@ -408,7 +408,7 @@ describe('ReactTypeScriptClass', function() {
408
it('warns when classic properties are defined on the instance, ' +
409
'but does not invoke them.', function() {
410
var warn = jest.genMockFn();
411
- console.warn = warn;
411
+ console.error = warn;
412
getInitialStateWasCalled = false;
413
test(React.createElement(ClassicProperties), 'SPAN', 'foo');
414
expect(getInitialStateWasCalled).toBe(false);
@@ -427,7 +427,7 @@ describe('ReactTypeScriptClass', function() {
427
428
it('should warn when mispelling shouldComponentUpdate', function() {
429
var warn = jest.genMockFn();
430
- console.warn = warn;
430
+ console.error = warn;
431
432
test(React.createElement(NamedComponent), 'SPAN', 'foo');
433
@@ -442,7 +442,7 @@ describe('ReactTypeScriptClass', function() {
442
443
it('should throw AND warn when trying to access classic APIs', function() {
444
var warn = jest.genMockFn();
445
- console.warn = warn;
445
+ console.error = warn;
446
var instance = test(
447
React.createElement(Inner, {name: 'foo'}),
448
'DIV','foo'
src/modern/element/__tests__/ReactJSXElement-test.js
+10
-10
@@ -86,37 +86,37 @@ describe('ReactJSXElement', function() {
86
});
87
88
it('merges JSX children onto the children prop', function() {
89
- spyOn(console, 'warn');
89
+ spyOn(console, 'error');
90
var a = 1;
91
var element = <Component children="text">{a}</Component>;
92
expect(element.props.children).toBe(a);
93
- expect(console.warn.argsForCall.length).toBe(0);
93
+ expect(console.error.argsForCall.length).toBe(0);
94
});
95
96
it('does not override children if no JSX children are provided', function() {
97
- spyOn(console, 'warn');
97
+ spyOn(console, 'error');
98
var element = <Component children="text" />;
99
expect(element.props.children).toBe('text');
100
- expect(console.warn.argsForCall.length).toBe(0);
100
+ expect(console.error.argsForCall.length).toBe(0);
101
});
102
103
it('overrides children if null is provided as a JSX child', function() {
104
- spyOn(console, 'warn');
104
+ spyOn(console, 'error');
105
var element = <Component children="text">{null}</Component>;
106
expect(element.props.children).toBe(null);
107
- expect(console.warn.argsForCall.length).toBe(0);
107
+ expect(console.error.argsForCall.length).toBe(0);
108
});
109
110
it('merges JSX children onto the children prop in an array', function() {
111
- spyOn(console, 'warn');
111
+ spyOn(console, 'error');
112
var a = 1, b = 2, c = 3;
113
var element = <Component>{a}{b}{c}</Component>;
114
expect(element.props.children).toEqual([1, 2, 3]);
115
- expect(console.warn.argsForCall.length).toBe(0);
115
+ expect(console.error.argsForCall.length).toBe(0);
116
});
117
118
it('allows static methods to be called using the type property', function() {
119
- spyOn(console, 'warn');
119
+ spyOn(console, 'error');
120
121
class Component {
122
static someStaticMethod() {
@@ -129,7 +129,7 @@ describe('ReactJSXElement', function() {
129
130
var element = <Component />;
131
expect(element.type.someStaticMethod()).toBe('someReturnValue');
132
- expect(console.warn.argsForCall.length).toBe(0);
132
+ expect(console.error.argsForCall.length).toBe(0);
133
});
134
135
it('identifies valid elements', function() {
src/modern/element/__tests__/ReactJSXElementValidator-test.js
+49
-49
@@ -38,18 +38,18 @@ describe('ReactJSXElementValidator', function() {
38
}
39
40
it('warns for keys for arrays of elements in children position', function() {
41
- spyOn(console, 'warn');
41
+ spyOn(console, 'error');
42
43
<Component>{[<Component />, <Component />]}</Component>;
44
45
- expect(console.warn.argsForCall.length).toBe(1);
46
- expect(console.warn.argsForCall[0][0]).toContain(
45
+ expect(console.error.argsForCall.length).toBe(1);
46
+ expect(console.error.argsForCall[0][0]).toContain(
47
'Each child in an array or iterator should have a unique "key" prop.'
48
);
49
});
50
51
it('warns for keys for arrays of elements with owner info', function() {
52
- spyOn(console, 'warn');
52
+ spyOn(console, 'error');
53
54
class InnerComponent {
55
render() {
@@ -69,8 +69,8 @@ describe('ReactJSXElementValidator', function() {
69
70
ReactTestUtils.renderIntoDocument(<ComponentWrapper />);
71
72
- expect(console.warn.argsForCall.length).toBe(1);
73
- expect(console.warn.argsForCall[0][0]).toContain(
72
+ expect(console.error.argsForCall.length).toBe(1);
73
+ expect(console.error.argsForCall[0][0]).toContain(
74
'Each child in an array or iterator should have a unique "key" prop. ' +
75
'Check the render method of InnerComponent. ' +
76
'It was passed a child from ComponentWrapper. '
@@ -78,7 +78,7 @@ describe('ReactJSXElementValidator', function() {
78
});
79
80
it('warns for keys for iterables of elements in rest args', function() {
81
- spyOn(console, 'warn');
81
+ spyOn(console, 'error');
82
83
var iterable = {
84
'@@iterator': function() {
@@ -94,22 +94,22 @@ describe('ReactJSXElementValidator', function() {
94
95
<Component>{iterable}</Component>;
96
97
- expect(console.warn.argsForCall.length).toBe(1);
98
- expect(console.warn.argsForCall[0][0]).toContain(
97
+ expect(console.error.argsForCall.length).toBe(1);
98
+ expect(console.error.argsForCall[0][0]).toContain(
99
'Each child in an array or iterator should have a unique "key" prop.'
100
);
101
});
102
103
it('does not warns for arrays of elements with keys', function() {
104
- spyOn(console, 'warn');
104
+ spyOn(console, 'error');
105
106
<Component>{[<Component key="#1" />, <Component key="#2" />]}</Component>;
107
108
- expect(console.warn.argsForCall.length).toBe(0);
108
+ expect(console.error.argsForCall.length).toBe(0);
109
});
110
111
it('does not warns for iterable elements with keys', function() {
112
- spyOn(console, 'warn');
112
+ spyOn(console, 'error');
113
114
var iterable = {
115
'@@iterator': function() {
@@ -128,22 +128,22 @@ describe('ReactJSXElementValidator', function() {
128
129
<Component>{iterable}</Component>
130
131
- expect(console.warn.argsForCall.length).toBe(0);
131
+ expect(console.error.argsForCall.length).toBe(0);
132
});
133
134
it('warns for numeric keys on objects as children', function() {
135
- spyOn(console, 'warn');
135
+ spyOn(console, 'error');
136
137
<Component>{frag({1: <Component />, 2: <Component />})}</Component>;
138
139
- expect(console.warn.argsForCall.length).toBe(1);
140
- expect(console.warn.argsForCall[0][0]).toContain(
139
+ expect(console.error.argsForCall.length).toBe(1);
140
+ expect(console.error.argsForCall[0][0]).toContain(
141
'Child objects should have non-numeric keys so ordering is preserved.'
142
);
143
});
144
145
it('does not warn for numeric keys in entry iterable as a child', function() {
146
- spyOn(console, 'warn');
146
+ spyOn(console, 'error');
147
148
var iterable = {
149
'@@iterator': function() {
@@ -160,23 +160,23 @@ describe('ReactJSXElementValidator', function() {
160
161
<Component>{iterable}</Component>;
162
163
- expect(console.warn.argsForCall.length).toBe(0);
163
+ expect(console.error.argsForCall.length).toBe(0);
164
});
165
166
it('does not warn when the element is directly as children', function() {
167
- spyOn(console, 'warn');
167
+ spyOn(console, 'error');
168
169
<Component><Component /><Component /></Component>;
170
171
- expect(console.warn.argsForCall.length).toBe(0);
171
+ expect(console.error.argsForCall.length).toBe(0);
172
});
173
174
it('does not warn when the child array contains non-elements', function() {
175
- spyOn(console, 'warn');
175
+ spyOn(console, 'error');
176
177
<Component>{[ {}, {} ]}</Component>;
178
179
- expect(console.warn.argsForCall.length).toBe(0);
179
+ expect(console.error.argsForCall.length).toBe(0);
180
});
181
182
// TODO: These warnings currently come from the composite component, but
@@ -186,7 +186,7 @@ describe('ReactJSXElementValidator', function() {
186
// In this test, we're making sure that if a proptype error is found in a
187
// component, we give a small hint as to which parent instantiated that
188
// component as per warnings about key usage in ReactElementValidator.
189
- spyOn(console, 'warn');
189
+ spyOn(console, 'error');
190
class MyComp {
191
render() {
192
return <div>My color is {this.color}</div>;
@@ -201,7 +201,7 @@ describe('ReactJSXElementValidator', function() {
201
}
202
}
203
ReactTestUtils.renderIntoDocument(<ParentComp />);
204
- expect(console.warn.calls[0].args[0]).toBe(
204
+ expect(console.error.calls[0].args[0]).toBe(
205
'Warning: Failed propType: ' +
206
'Invalid prop `color` of type `number` supplied to `MyComp`, ' +
207
'expected `string`. Check the render method of `ParentComp`.'
@@ -212,24 +212,24 @@ describe('ReactJSXElementValidator', function() {
212
var Undefined = undefined;
213
var Null = null;
214
var Div = 'div';
215
- spyOn(console, 'warn');
215
+ spyOn(console, 'error');
216
<Undefined />;
217
<Null />;
218
- expect(console.warn.calls.length).toBe(2);
219
- expect(console.warn.calls[0].args[0]).toContain(
218
+ expect(console.error.calls.length).toBe(2);
219
+ expect(console.error.calls[0].args[0]).toContain(
220
'type should not be null or undefined. It should be a string (for ' +
221
'DOM elements) or a ReactClass (for composite components).'
222
);
223
- expect(console.warn.calls[1].args[0]).toContain(
223
+ expect(console.error.calls[1].args[0]).toContain(
224
'type should not be null or undefined. It should be a string (for ' +
225
'DOM elements) or a ReactClass (for composite components).'
226
);
227
<Div />;
228
- expect(console.warn.calls.length).toBe(2);
228
+ expect(console.error.calls.length).toBe(2);
229
});
230
231
it('should check default prop values', function() {
232
- spyOn(console, 'warn');
232
+ spyOn(console, 'error');
233
234
class Component {
235
render() {
@@ -241,15 +241,15 @@ describe('ReactJSXElementValidator', function() {
241
242
ReactTestUtils.renderIntoDocument(<Component />);
243
244
- expect(console.warn.calls.length).toBe(1);
245
- expect(console.warn.calls[0].args[0]).toBe(
244
+ expect(console.error.calls.length).toBe(1);
245
+ expect(console.error.calls[0].args[0]).toBe(
246
'Warning: Failed propType: ' +
247
'Required prop `prop` was not specified in `Component`.'
248
);
249
});
250
251
it('should not check the default for explicit null', function() {
252
- spyOn(console, 'warn');
252
+ spyOn(console, 'error');
253
254
class Component {
255
render() {
@@ -261,15 +261,15 @@ describe('ReactJSXElementValidator', function() {
261
262
ReactTestUtils.renderIntoDocument(<Component prop={null} />);
263
264
- expect(console.warn.calls.length).toBe(1);
265
- expect(console.warn.calls[0].args[0]).toBe(
264
+ expect(console.error.calls.length).toBe(1);
265
+ expect(console.error.calls[0].args[0]).toBe(
266
'Warning: Failed propType: ' +
267
'Required prop `prop` was not specified in `Component`.'
268
);
269
});
270
271
it('should check declared prop types', function() {
272
- spyOn(console, 'warn');
272
+ spyOn(console, 'error');
273
274
class Component {
275
render() {
@@ -283,13 +283,13 @@ describe('ReactJSXElementValidator', function() {
283
ReactTestUtils.renderIntoDocument(<Component />);
284
ReactTestUtils.renderIntoDocument(<Component prop={42} />);
285
286
- expect(console.warn.calls.length).toBe(2);
287
- expect(console.warn.calls[0].args[0]).toBe(
286
+ expect(console.error.calls.length).toBe(2);
287
+ expect(console.error.calls[0].args[0]).toBe(
288
'Warning: Failed propType: ' +
289
'Required prop `prop` was not specified in `Component`.'
290
);
291
292
- expect(console.warn.calls[1].args[0]).toBe(
292
+ expect(console.error.calls[1].args[0]).toBe(
293
'Warning: Failed propType: ' +
294
'Invalid prop `prop` of type `number` supplied to ' +
295
'`Component`, expected `string`.'
@@ -298,7 +298,7 @@ describe('ReactJSXElementValidator', function() {
298
ReactTestUtils.renderIntoDocument(<Component prop="string" />);
299
300
// Should not error for strings
301
- expect(console.warn.calls.length).toBe(2);
301
+ expect(console.error.calls.length).toBe(2);
302
});
303
304
it('should warn on invalid prop types', function() {
@@ -306,7 +306,7 @@ describe('ReactJSXElementValidator', function() {
306
// for us to issue a warning earlier than element creation when the error
307
// actually occurs. Since this step is skipped in production, we should just
308
// warn instead of throwing for this case.
309
- spyOn(console, 'warn');
309
+ spyOn(console, 'error');
310
class Component {
311
render() {
312
return <span>{this.props.prop}</span>;
@@ -316,15 +316,15 @@ describe('ReactJSXElementValidator', function() {
316
prop: null
317
};
318
ReactTestUtils.renderIntoDocument(<Component />);
319
- expect(console.warn.calls.length).toBe(1);
320
- expect(console.warn.calls[0].args[0]).toContain(
319
+ expect(console.error.calls.length).toBe(1);
320
+ expect(console.error.calls[0].args[0]).toContain(
321
'Invariant Violation: Component: prop type `prop` is invalid; ' +
322
'it must be a function, usually from React.PropTypes.'
323
);
324
});
325
326
it('should warn on invalid context types', function() {
327
- spyOn(console, 'warn');
327
+ spyOn(console, 'error');
328
class Component {
329
render() {
330
return <span>{this.props.prop}</span>;
@@ -334,15 +334,15 @@ describe('ReactJSXElementValidator', function() {
334
prop: null
335
};
336
ReactTestUtils.renderIntoDocument(<Component />);
337
- expect(console.warn.calls.length).toBe(1);
338
- expect(console.warn.calls[0].args[0]).toContain(
337
+ expect(console.error.calls.length).toBe(1);
338
+ expect(console.error.calls[0].args[0]).toContain(
339
'Invariant Violation: Component: context type `prop` is invalid; ' +
340
'it must be a function, usually from React.PropTypes.'
341
);
342
});
343
344
it('should warn if getDefaultProps is specificed on the class', function() {
345
- spyOn(console, 'warn');
345
+ spyOn(console, 'error');
346
class Component {
347
render() {
348
return <span>{this.props.prop}</span>;
@@ -352,8 +352,8 @@ describe('ReactJSXElementValidator', function() {
352
prop: 'foo'
353
});
354
ReactTestUtils.renderIntoDocument(<Component />);
355
- expect(console.warn.calls.length).toBe(1);
356
- expect(console.warn.calls[0].args[0]).toContain(
355
+ expect(console.error.calls.length).toBe(1);
356
+ expect(console.error.calls[0].args[0]).toContain(
357
'getDefaultProps is only used on classic React.createClass definitions.' +
358
' Use a static property named `defaultProps` instead.'
359
);
src/test/__tests__/ReactTestUtils-test.js
+5
-5
@@ -25,12 +25,12 @@ describe('ReactTestUtils', function() {
25
React = require('React');
26
ReactTestUtils = require('ReactTestUtils');
27
28
- warn = console.warn;
29
- console.warn = mocks.getMockFunction();
28
+ warn = console.error;
29
+ console.error = mocks.getMockFunction();
30
});
31
32
afterEach(function() {
33
- console.warn = warn;
33
+ console.error = warn;
34
});
35
36
it('should have shallow rendering', function() {
@@ -193,7 +193,7 @@ describe('ReactTestUtils', function() {
193
}
194
}
195
196
- spyOn(console, 'warn');
196
+ spyOn(console, 'error');
197
198
var foo = ReactTestUtils.renderIntoDocument(<Foo />);
199
expect(ReactTestUtils.isDOMComponent(foo)).toBe(false);
@@ -204,7 +204,7 @@ describe('ReactTestUtils', function() {
204
var div = ReactTestUtils.renderIntoDocument(<div />);
205
expect(ReactTestUtils.isDOMComponent(div)).toBe(true);
206
207
- expect(console.warn.calls.length).toBe(0);
207
+ expect(console.error.calls.length).toBe(0);
208
});
209
210
it('should support injected wrapper components as DOM components', function() {
src/utils/__tests__/ReactChildren-test.js
+10
-10
@@ -350,10 +350,10 @@ describe('ReactChildren', function() {
350
<div>{zero}{one}</div>
351
);
352
353
- spyOn(console, 'warn');
353
+ spyOn(console, 'error');
354
var mapped = ReactChildren.map(instance.props.children, mapFn);
355
356
- expect(console.warn.calls.length).toEqual(1);
356
+ expect(console.error.calls.length).toEqual(1);
357
expect(nthChild(mapped, 0)).toBe(zero);
358
expect(keyOfNthChild(mapped, 0)).toBe('.$something');
359
});
@@ -422,17 +422,17 @@ describe('ReactChildren', function() {
422
});
423
424
it('should warn if a fragment is used without the wrapper', function() {
425
- spyOn(console, 'warn');
425
+ spyOn(console, 'error');
426
var child = React.createElement('span');
427
ReactChildren.forEach({a: child, b: child}, function(c) {
428
expect(c).toBe(child);
429
});
430
- expect(console.warn.calls.length).toBe(1);
431
- expect(console.warn.calls[0].args[0]).toContain('use of a keyed object');
430
+ expect(console.error.calls.length).toBe(1);
431
+ expect(console.error.calls[0].args[0]).toContain('use of a keyed object');
432
});
433
434
it('should warn if a fragment is accessed', function() {
435
- spyOn(console, 'warn');
435
+ spyOn(console, 'error');
436
var child = React.createElement('span');
437
var frag = ReactChildren.map([child, child], function(c) {
438
return c;
@@ -441,8 +441,8 @@ describe('ReactChildren', function() {
441
frag[key];
442
break;
443
}
444
- expect(console.warn.calls.length).toBe(1);
445
- expect(console.warn.calls[0].args[0]).toContain('is an opaque type');
444
+ expect(console.error.calls.length).toBe(1);
445
+ expect(console.error.calls[0].args[0]).toContain('is an opaque type');
446
447
var frag2 = ReactChildren.map([child, child], function(c) {
448
return c;
@@ -451,8 +451,8 @@ describe('ReactChildren', function() {
451
frag2[key] = 123;
452
break;
453
}
454
- expect(console.warn.calls.length).toBe(2);
455
- expect(console.warn.calls[1].args[0]).toContain('is an immutable opaque');
454
+ expect(console.error.calls.length).toBe(2);
455
+ expect(console.error.calls[1].args[0]).toContain('is an immutable opaque');
456
});
457
458
});
src/utils/__tests__/cloneWithProps-test.js
+2
-2
@@ -82,7 +82,7 @@ describe('cloneWithProps', function() {
82
});
83
84
it('should warn when cloning with refs', function() {
85
- spyOn(console, 'warn');
85
+ spyOn(console, 'error');
86
87
var Grandparent = React.createClass({
88
render: function() {
@@ -101,7 +101,7 @@ describe('cloneWithProps', function() {
101
102
var component = ReactTestUtils.renderIntoDocument(<Grandparent />);
103
expect(component.refs).toBe(emptyObject);
104
- expect(console.warn.argsForCall.length).toBe(1);
104
+ expect(console.error.argsForCall.length).toBe(1);
105
});
106
107
it('should transfer the key property', function() {
src/utils/__tests__/traverseAllChildren-test.js
+3
-3
@@ -396,7 +396,7 @@ describe('traverseAllChildren', function() {
396
});
397
398
it('should use keys from entry iterables', function() {
399
- spyOn(console, 'warn');
399
+ spyOn(console, 'error');
400
401
var threeDivEntryIterable = {
402
'@@iterator': function() {
@@ -448,8 +448,8 @@ describe('traverseAllChildren', function() {
448
2
449
);
450
451
- expect(console.warn.argsForCall.length).toBe(1);
452
- expect(console.warn.argsForCall[0][0]).toContain(
451
+ expect(console.error.argsForCall.length).toBe(1);
452
+ expect(console.error.argsForCall[0][0]).toContain(
453
'Warning: Using Maps as children is not yet fully supported. It is an ' +
454
'experimental feature that might be removed. Convert it to a sequence ' +
455
'/ iterable of keyed ReactElements instead.'
src/vendor/core/warning.js
+1
-1
@@ -46,7 +46,7 @@ if (__DEV__) {
46
var argIndex = 0;
47
var message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]);
48
if (typeof console !== 'undefined') {
49
- console.warn(message);
49
+ console.error(message);
50
}
51
try {
52
// --- Welcome to debugging React ---