update to use spyOn for console.warn #2749
Kevin Old committed
Jan 25, 2015 at 22:38 UTC
f0ea2b59797f4abf3149cdcb2f995c2e4164d8a2
7 files changed
+164
-231
src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js
+2
-3
@@ -26,6 +26,7 @@ describe('ReactCSSTransitionGroup', function() {
26
mocks = require('mocks');
27
28
container = document.createElement('div');
29
+ spyOn(console, 'warn');
30
});
31
32
it('should warn after time with no transitionend', function() {
@@ -49,8 +50,6 @@ describe('ReactCSSTransitionGroup', function() {
50
expect(a.getDOMNode().childNodes[0].id).toBe('two');
51
expect(a.getDOMNode().childNodes[1].id).toBe('one');
52
52
- console.warn = mocks.getMockFunction();
53
-
53
// For some reason jst is adding extra setTimeout()s and grunt test isn't,
54
// so we need to do this disgusting hack.
55
for (var i = 0 ; i < setTimeout.mock.calls.length; i++) {
@@ -61,7 +60,7 @@ describe('ReactCSSTransitionGroup', function() {
60
}
61
62
expect(a.getDOMNode().childNodes.length).toBe(2);
64
- expect(console.warn.mock.calls.length).toBe(1);
63
+ expect(console.warn.argsForCall.length).toBe(1);
64
});
65
66
it('should keep both sets of DOM nodes around', function() {
src/browser/server/__tests__/ReactServerRendering-test.js
+2
-4
@@ -48,6 +48,7 @@ describe('ReactServerRendering', function() {
48
49
var DOMProperty = require('DOMProperty');
50
ID_ATTRIBUTE_NAME = DOMProperty.ID_ATTRIBUTE_NAME;
51
+ spyOn(console, 'warn');
52
});
53
54
describe('renderToString', function() {
@@ -215,15 +216,12 @@ describe('ReactServerRendering', function() {
216
217
// Now simulate a situation where the app is not idempotent. React should
218
// warn but do the right thing.
218
- var _warn = console.warn;
219
- console.warn = mocks.getMockFunction();
219
element.innerHTML = lastMarkup;
220
var instance = React.render(<TestComponent name="y" />, element);
221
expect(mountCount).toEqual(4);
223
- expect(console.warn.mock.calls.length).toBe(1);
222
+ expect(console.warn.argsForCall.length).toBe(1);
223
expect(element.innerHTML.length > 0).toBe(true);
224
expect(element.innerHTML).not.toEqual(lastMarkup);
226
- console.warn = _warn;
225
226
// Ensure the events system works
227
expect(numClicks).toEqual(0);
src/browser/ui/dom/components/__tests__/ReactDOMInput-test.js
+50
-77
@@ -25,6 +25,7 @@ describe('ReactDOMInput', function() {
25
React = require('React');
26
ReactLink = require('ReactLink');
27
ReactTestUtils = require('ReactTestUtils');
28
+ spyOn(console, 'warn');
29
});
30
31
it('should display `defaultValue` of number 0', function() {
@@ -212,42 +213,28 @@ describe('ReactDOMInput', function() {
213
});
214
215
it('should warn with value and no onChange handler', function() {
215
- var oldWarn = console.warn;
216
- try {
217
- console.warn = mocks.getMockFunction();
218
-
219
- var link = new ReactLink('yolo', mocks.getMockFunction());
220
- ReactTestUtils.renderIntoDocument(<input type="text" valueLink={link} />);
221
- expect(console.warn.mock.calls.length).toBe(0);
222
-
223
- ReactTestUtils.renderIntoDocument(
224
- <input type="text" value="zoink" onChange={mocks.getMockFunction()} />
225
- );
226
- expect(console.warn.mock.calls.length).toBe(0);
227
- ReactTestUtils.renderIntoDocument(<input type="text" value="zoink" />);
228
- expect(console.warn.mock.calls.length).toBe(1);
229
- } finally {
230
- console.warn = oldWarn;
231
- }
216
+ var link = new ReactLink('yolo', mocks.getMockFunction());
217
+ ReactTestUtils.renderIntoDocument(<input type="text" valueLink={link} />);
218
+ expect(console.warn.argsForCall.length).toBe(0);
219
+
220
+ ReactTestUtils.renderIntoDocument(
221
+ <input type="text" value="zoink" onChange={mocks.getMockFunction()} />
222
+ );
223
+ expect(console.warn.argsForCall.length).toBe(0);
224
+ ReactTestUtils.renderIntoDocument(<input type="text" value="zoink" />);
225
+ expect(console.warn.argsForCall.length).toBe(1);
226
});
227
228
it('should warn with value and no onChange handler and readOnly specified', function() {
235
- var oldWarn = console.warn;
236
- try {
237
- console.warn = mocks.getMockFunction();
238
-
239
- ReactTestUtils.renderIntoDocument(
240
- <input type="text" value="zoink" readOnly={true} />
241
- );
242
- expect(console.warn.mock.calls.length).toBe(0);
243
-
244
- ReactTestUtils.renderIntoDocument(
245
- <input type="text" value="zoink" readOnly={false} />
246
- );
247
- expect(console.warn.mock.calls.length).toBe(1);
248
- } finally {
249
- console.warn = oldWarn;
250
- }
229
+ ReactTestUtils.renderIntoDocument(
230
+ <input type="text" value="zoink" readOnly={true} />
231
+ );
232
+ expect(console.warn.argsForCall.length).toBe(0);
233
+
234
+ ReactTestUtils.renderIntoDocument(
235
+ <input type="text" value="zoink" readOnly={false} />
236
+ );
237
+ expect(console.warn.argsForCall.length).toBe(1);
238
});
239
240
it('should throw if both value and valueLink are provided', function() {
@@ -294,53 +281,39 @@ describe('ReactDOMInput', function() {
281
});
282
283
it('should warn with checked and no onChange handler', function() {
297
- var oldWarn = console.warn;
298
- try {
299
- console.warn = mocks.getMockFunction();
300
-
301
- var node = document.createElement('div');
302
- var link = new ReactLink(true, mocks.getMockFunction());
303
- React.render(<input type="checkbox" checkedLink={link} />, node);
304
- expect(console.warn.mock.calls.length).toBe(0);
305
-
306
- ReactTestUtils.renderIntoDocument(
307
- <input
308
- type="checkbox"
309
- checked="false"
310
- onChange={mocks.getMockFunction()}
311
- />
312
- );
313
- expect(console.warn.mock.calls.length).toBe(0);
314
-
315
- ReactTestUtils.renderIntoDocument(
316
- <input type="checkbox" checked="false" readOnly={true} />
317
- );
318
- expect(console.warn.mock.calls.length).toBe(0);
319
-
320
- ReactTestUtils.renderIntoDocument(<input type="checkbox" checked="false" />);
321
- expect(console.warn.mock.calls.length).toBe(1);
322
- } finally {
323
- console.warn = oldWarn;
324
- }
284
+ var node = document.createElement('div');
285
+ var link = new ReactLink(true, mocks.getMockFunction());
286
+ React.render(<input type="checkbox" checkedLink={link} />, node);
287
+ expect(console.warn.argsForCall.length).toBe(0);
288
+
289
+ ReactTestUtils.renderIntoDocument(
290
+ <input
291
+ type="checkbox"
292
+ checked="false"
293
+ onChange={mocks.getMockFunction()}
294
+ />
295
+ );
296
+ expect(console.warn.argsForCall.length).toBe(0);
297
+
298
+ ReactTestUtils.renderIntoDocument(
299
+ <input type="checkbox" checked="false" readOnly={true} />
300
+ );
301
+ expect(console.warn.argsForCall.length).toBe(0);
302
+
303
+ ReactTestUtils.renderIntoDocument(<input type="checkbox" checked="false" />);
304
+ expect(console.warn.argsForCall.length).toBe(1);
305
});
306
307
it('should warn with checked and no onChange handler with readOnly specified', function() {
328
- var oldWarn = console.warn;
329
- try {
330
- console.warn = mocks.getMockFunction();
331
-
332
- ReactTestUtils.renderIntoDocument(
333
- <input type="checkbox" checked="false" readOnly={true} />
334
- );
335
- expect(console.warn.mock.calls.length).toBe(0);
336
-
337
- ReactTestUtils.renderIntoDocument(
338
- <input type="checkbox" checked="false" readOnly={false} />
339
- );
340
- expect(console.warn.mock.calls.length).toBe(1);
341
- } finally {
342
- console.warn = oldWarn;
343
- }
308
+ ReactTestUtils.renderIntoDocument(
309
+ <input type="checkbox" checked="false" readOnly={true} />
310
+ );
311
+ expect(console.warn.argsForCall.length).toBe(0);
312
+
313
+ ReactTestUtils.renderIntoDocument(
314
+ <input type="checkbox" checked="false" readOnly={false} />
315
+ );
316
+ expect(console.warn.argsForCall.length).toBe(1);
317
});
318
319
it('should throw if both checked and checkedLink are provided', 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
- console.warn = mocks.getMockFunction();
35
+ spyOn(console, 'warn');
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.mock.calls.length).toBe(1);
149
- expect(console.warn.mock.calls[0][0]).toBe(
148
+ expect(console.warn.argsForCall.length).toBe(1);
149
+ expect(console.warn.argsForCall[0][0]).toBe(
150
'Warning: Required context `foo` was not specified in `Component`.'
151
);
152
@@ -171,7 +171,7 @@ describe('ReactContextValidator', function() {
171
);
172
173
// Previous call should not error
174
- expect(console.warn.mock.calls.length).toBe(1);
174
+ expect(console.warn.argsForCall.length).toBe(1);
175
176
var ComponentInFooNumberContext = React.createClass({
177
childContextTypes: {
@@ -191,8 +191,8 @@ describe('ReactContextValidator', function() {
191
192
ReactTestUtils.renderIntoDocument(<ComponentInFooNumberContext fooValue={123} />);
193
194
- expect(console.warn.mock.calls.length).toBe(2);
195
- expect(console.warn.mock.calls[1][0]).toBe(
194
+ expect(console.warn.argsForCall.length).toBe(2);
195
+ expect(console.warn.argsForCall[1][0]).toBe(
196
'Warning: Invalid context `foo` of type `number` supplied ' +
197
'to `Component`, expected `string`.' +
198
' Check the render method of `ComponentInFooNumberContext`.'
@@ -216,18 +216,18 @@ describe('ReactContextValidator', function() {
216
});
217
218
ReactTestUtils.renderIntoDocument(<Component testContext={{bar: 123}} />);
219
- expect(console.warn.mock.calls.length).toBe(2);
220
- expect(console.warn.mock.calls[0][0]).toBe(
219
+ expect(console.warn.argsForCall.length).toBe(2);
220
+ expect(console.warn.argsForCall[0][0]).toBe(
221
'Warning: Required child context `foo` was not specified in `Component`.'
222
);
223
- expect(console.warn.mock.calls[1][0]).toBe(
223
+ expect(console.warn.argsForCall[1][0]).toBe(
224
'Warning: Required child context `foo` was not specified in `Component`.'
225
);
226
227
ReactTestUtils.renderIntoDocument(<Component testContext={{foo: 123}} />);
228
229
- expect(console.warn.mock.calls.length).toBe(4);
230
- expect(console.warn.mock.calls[3][0]).toBe(
229
+ expect(console.warn.argsForCall.length).toBe(4);
230
+ expect(console.warn.argsForCall[3][0]).toBe(
231
'Warning: Invalid child context `foo` of type `number` ' +
232
'supplied to `Component`, expected `string`.'
233
);
@@ -241,7 +241,7 @@ describe('ReactContextValidator', function() {
241
);
242
243
// Previous calls should not log errors
244
- expect(console.warn.mock.calls.length).toBe(4);
244
+ expect(console.warn.argsForCall.length).toBe(4);
245
});
246
247
});
src/classic/class/__tests__/ReactClass-test.js
+64
-77
@@ -21,6 +21,7 @@ describe('ReactClass-spec', function() {
21
beforeEach(function() {
22
React = require('React');
23
ReactTestUtils = require('ReactTestUtils');
24
+ spyOn(console, 'warn');
25
});
26
27
it('should throw when `render` is not specified', function() {
@@ -49,10 +50,9 @@ describe('ReactClass-spec', function() {
50
return <div />;
51
}
52
});
52
- console.warn = mocks.getMockFunction();
53
expect(TestComponent.type).toBe(TestComponent);
54
- expect(console.warn.mock.calls.length).toBe(1);
55
- expect(console.warn.mock.calls[0][0]).toBe(
54
+ expect(console.warn.argsForCall.length).toBe(1);
55
+ expect(console.warn.argsForCall[0][0]).toBe(
56
'Warning: TestComponent.type is deprecated. Use TestComponent ' +
57
'directly to access the class.'
58
);
@@ -126,44 +126,37 @@ describe('ReactClass-spec', function() {
126
});
127
128
it('should warn when mispelling shouldComponentUpdate', function() {
129
- var warn = console.warn;
130
- console.warn = mocks.getMockFunction();
131
-
132
- try {
133
- React.createClass({
134
- componentShouldUpdate: function() {
135
- return false;
136
- },
137
- render: function() {
138
- return <div />;
139
- }
140
- });
141
- expect(console.warn.mock.calls.length).toBe(1);
142
- expect(console.warn.mock.calls[0][0]).toBe(
143
- 'A component has a method called componentShouldUpdate(). Did you ' +
144
- 'mean shouldComponentUpdate()? The name is phrased as a question ' +
145
- 'because the function is expected to return a value.'
146
- );
129
+ React.createClass({
130
+ componentShouldUpdate: function() {
131
+ return false;
132
+ },
133
+ render: function() {
134
+ return <div />;
135
+ }
136
+ });
137
+ expect(console.warn.argsForCall.length).toBe(1);
138
+ expect(console.warn.argsForCall[0][0]).toBe(
139
+ 'A component has a method called componentShouldUpdate(). Did you ' +
140
+ 'mean shouldComponentUpdate()? The name is phrased as a question ' +
141
+ 'because the function is expected to return a value.'
142
+ );
143
148
- var NamedComponent = React.createClass({
149
- componentShouldUpdate: function() {
150
- return false;
151
- },
152
- render: function() {
153
- return <div />;
154
- }
155
- });
156
- expect(console.warn.mock.calls.length).toBe(2);
157
- expect(console.warn.mock.calls[1][0]).toBe(
158
- 'NamedComponent has a method called componentShouldUpdate(). Did you ' +
159
- 'mean shouldComponentUpdate()? The name is phrased as a question ' +
160
- 'because the function is expected to return a value.'
161
- );
144
+ var NamedComponent = React.createClass({
145
+ componentShouldUpdate: function() {
146
+ return false;
147
+ },
148
+ render: function() {
149
+ return <div />;
150
+ }
151
+ });
152
+ expect(console.warn.argsForCall.length).toBe(2);
153
+ expect(console.warn.argsForCall[1][0]).toBe(
154
+ 'NamedComponent has a method called componentShouldUpdate(). Did you ' +
155
+ 'mean shouldComponentUpdate()? The name is phrased as a question ' +
156
+ 'because the function is expected to return a value.'
157
+ );
158
163
- <NamedComponent />; // Shut up lint
164
- } finally {
165
- console.warn = warn;
166
- }
159
+ <NamedComponent />; // Shut up lint
160
});
161
162
it('should throw if a reserved property is in statics', function() {
@@ -192,44 +185,38 @@ describe('ReactClass-spec', function() {
185
// TODO: Consider actually moving these to statics or drop this unit test.
186
187
xit('should warn when using deprecated non-static spec keys', function() {
195
- var warn = console.warn;
196
- console.warn = mocks.getMockFunction();
197
- try {
198
- React.createClass({
199
- mixins: [{}],
200
- propTypes: {
201
- foo: React.PropTypes.string
202
- },
203
- contextTypes: {
204
- foo: React.PropTypes.string
205
- },
206
- childContextTypes: {
207
- foo: React.PropTypes.string
208
- },
209
- render: function() {
210
- return <div />;
211
- }
212
- });
213
- expect(console.warn.mock.calls.length).toBe(4);
214
- expect(console.warn.mock.calls[0][0]).toBe(
215
- 'createClass(...): `mixins` is now a static property and should ' +
216
- 'be defined inside "statics".'
217
- );
218
- expect(console.warn.mock.calls[1][0]).toBe(
219
- 'createClass(...): `propTypes` is now a static property and should ' +
220
- 'be defined inside "statics".'
221
- );
222
- expect(console.warn.mock.calls[2][0]).toBe(
223
- 'createClass(...): `contextTypes` is now a static property and ' +
224
- 'should be defined inside "statics".'
225
- );
226
- expect(console.warn.mock.calls[3][0]).toBe(
227
- 'createClass(...): `childContextTypes` is now a static property and ' +
228
- 'should be defined inside "statics".'
229
- );
230
- } finally {
231
- console.warn = warn;
232
- }
188
+ React.createClass({
189
+ mixins: [{}],
190
+ propTypes: {
191
+ foo: React.PropTypes.string
192
+ },
193
+ contextTypes: {
194
+ foo: React.PropTypes.string
195
+ },
196
+ childContextTypes: {
197
+ foo: React.PropTypes.string
198
+ },
199
+ render: function() {
200
+ return <div />;
201
+ }
202
+ });
203
+ expect(console.warn.argsForCall.length).toBe(4);
204
+ expect(console.warn.argsForCall[0][0]).toBe(
205
+ 'createClass(...): `mixins` is now a static property and should ' +
206
+ 'be defined inside "statics".'
207
+ );
208
+ expect(console.warn.argsForCall[1][0]).toBe(
209
+ 'createClass(...): `propTypes` is now a static property and should ' +
210
+ 'be defined inside "statics".'
211
+ );
212
+ expect(console.warn.argsForCall[2][0]).toBe(
213
+ 'createClass(...): `contextTypes` is now a static property and ' +
214
+ 'should be defined inside "statics".'
215
+ );
216
+ expect(console.warn.argsForCall[3][0]).toBe(
217
+ 'createClass(...): `childContextTypes` is now a static property and ' +
218
+ 'should be defined inside "statics".'
219
+ );
220
});
221
222
it('should support statics', function() {
src/core/__tests__/ReactCompositeComponent-test.js
+29
-47
@@ -24,8 +24,6 @@ var ReactTestUtils;
24
var cx;
25
var reactComponentExpect;
26
var mocks;
27
-var warn;
28
-
27
28
describe('ReactCompositeComponent', function() {
29
@@ -75,12 +73,7 @@ describe('ReactCompositeComponent', function() {
73
}
74
});
75
78
- warn = console.warn;
79
- console.warn = mocks.getMockFunction();
80
- });
81
-
82
- afterEach(function() {
83
- console.warn = warn;
76
+ spyOn(console, 'warn');
77
});
78
79
it('should support rendering to different child types over time', function() {
@@ -118,7 +111,6 @@ describe('ReactCompositeComponent', function() {
111
var container = document.createElement('div');
112
container.innerHTML = markup;
113
121
- spyOn(console, 'warn');
114
React.render(<Parent />, container);
115
expect(console.warn).not.toHaveBeenCalled();
116
});
@@ -161,8 +153,6 @@ describe('ReactCompositeComponent', function() {
153
});
154
155
it('should auto bind methods and values correctly', function() {
164
- spyOn(console, 'warn');
165
-
156
var ComponentClass = React.createClass({
157
getInitialState: function() {
158
return {valueToReturn: 'hi'};
@@ -470,35 +460,28 @@ describe('ReactCompositeComponent', function() {
460
});
461
462
it('should warn when shouldComponentUpdate() returns undefined', function() {
473
- var warn = console.warn;
474
- console.warn = mocks.getMockFunction();
463
+ var Component = React.createClass({
464
+ getInitialState: function () {
465
+ return {bogus: false};
466
+ },
467
476
- try {
477
- var Component = React.createClass({
478
- getInitialState: function () {
479
- return {bogus: false};
480
- },
468
+ shouldComponentUpdate: function() {
469
+ return undefined;
470
+ },
471
482
- shouldComponentUpdate: function() {
483
- return undefined;
484
- },
472
+ render: function() {
473
+ return <div />;
474
+ }
475
+ });
476
486
- render: function() {
487
- return <div />;
488
- }
489
- });
490
-
491
- var instance = ReactTestUtils.renderIntoDocument(<Component />);
492
- instance.setState({bogus: true});
493
-
494
- expect(console.warn.mock.calls.length).toBe(1);
495
- expect(console.warn.mock.calls[0][0]).toBe(
496
- 'Component.shouldComponentUpdate(): Returned undefined instead of a ' +
497
- 'boolean value. Make sure to return true or false.'
498
- );
499
- } finally {
500
- console.warn = warn;
501
- }
477
+ var instance = ReactTestUtils.renderIntoDocument(<Component />);
478
+ instance.setState({bogus: true});
479
+
480
+ expect(console.warn.argsForCall.length).toBe(1);
481
+ expect(console.warn.argsForCall[0][0]).toBe(
482
+ 'Component.shouldComponentUpdate(): Returned undefined instead of a ' +
483
+ 'boolean value. Make sure to return true or false.'
484
+ );
485
});
486
487
it('should pass context', function() {
@@ -579,8 +562,8 @@ describe('ReactCompositeComponent', function() {
562
563
// Two warnings, one for the component and one for the div
564
// We may want to make this expect one warning in the future
582
- expect(console.warn.mock.calls.length).toBe(1);
583
- expect(console.warn.mock.calls[0][0]).toBe(
565
+ expect(console.warn.argsForCall.length).toBe(1);
566
+ expect(console.warn.argsForCall[0][0]).toBe(
567
'Warning: owner-based and parent-based contexts differ '+
568
'(values: `bar` vs `undefined`) for key (foo) '+
569
'while mounting Component (see: http://fb.me/react-context-by-parent)'
@@ -622,8 +605,8 @@ describe('ReactCompositeComponent', function() {
605
606
// Two warnings, one for the component and one for the div
607
// We may want to make this expect one warning in the future
625
- expect(console.warn.mock.calls.length).toBe(1);
626
- expect(console.warn.mock.calls[0][0]).toBe(
608
+ expect(console.warn.argsForCall.length).toBe(1);
609
+ expect(console.warn.argsForCall[0][0]).toBe(
610
'Warning: owner-based and parent-based contexts differ ' +
611
'(values: `noise` vs `bar`) for key (foo) while mounting Component ' +
612
'(see: http://fb.me/react-context-by-parent)'
@@ -665,7 +648,7 @@ describe('ReactCompositeComponent', function() {
648
});
649
React.render(<Parent>{componentWithSameContext}</Parent>, div);
650
668
- expect(console.warn.mock.calls.length).toBe(0);
651
+ expect(console.warn.argsForCall.length).toBe(0);
652
653
var componentWithDifferentContext = React.withContext({foo: 'noise'}, function() {
654
return <Component />;
@@ -674,8 +657,8 @@ describe('ReactCompositeComponent', function() {
657
658
// Two warnings, one for the component and one for the div
659
// We may want to make this expect one warning in the future
677
- expect(console.warn.mock.calls.length).toBe(1);
678
- expect(console.warn.mock.calls[0][0]).toBe(
660
+ expect(console.warn.argsForCall.length).toBe(1);
661
+ expect(console.warn.argsForCall[0][0]).toBe(
662
'Warning: owner-based and parent-based contexts differ ' +
663
'(values: `noise` vs `bar`) for key (foo) while mounting Component ' +
664
'(see: http://fb.me/react-context-by-parent)'
@@ -728,8 +711,8 @@ describe('ReactCompositeComponent', function() {
711
712
// Two warnings, one for the component and one for the div
713
// We may want to make this expect one warning in the future
731
- expect(console.warn.mock.calls.length).toBe(1);
732
- expect(console.warn.mock.calls[0][0]).toBe(
714
+ expect(console.warn.argsForCall.length).toBe(1);
715
+ expect(console.warn.argsForCall[0][0]).toBe(
716
'Warning: owner-based and parent-based contexts differ ' +
717
'(values: `noise` vs `bar`) for key (foo) while mounting Component ' +
718
'(see: http://fb.me/react-context-by-parent)'
@@ -810,7 +793,6 @@ describe('ReactCompositeComponent', function() {
793
});
794
795
it('should disallow nested render calls', function() {
813
- spyOn(console, 'warn');
796
var Inner = React.createClass({
797
render: function() {
798
return <div />;
src/utils/__tests__/cloneWithProps-test.js
+5
-11
@@ -82,6 +82,8 @@ describe('cloneWithProps', function() {
82
});
83
84
it('should warn when cloning with refs', function() {
85
+ spyOn(console, 'warn');
86
+
87
var Grandparent = React.createClass({
88
render: function() {
89
return <Parent><div ref="yolo" /></Parent>;
@@ -97,17 +99,9 @@ describe('cloneWithProps', function() {
99
}
100
});
101
100
- var _warn = console.warn;
101
-
102
- try {
103
- console.warn = mocks.getMockFunction();
104
-
105
- var component = ReactTestUtils.renderIntoDocument(<Grandparent />);
106
- expect(component.refs).toBe(emptyObject);
107
- expect(console.warn.mock.calls.length).toBe(1);
108
- } finally {
109
- console.warn = _warn;
110
- }
102
+ var component = ReactTestUtils.renderIntoDocument(<Grandparent />);
103
+ expect(component.refs).toBe(emptyObject);
104
+ expect(console.warn.argsForCall.length).toBe(1);
105
});
106
107
it('should transfer the key property', function() {