@samitouri / QOS-React-2 / commits / 967435b249

Revert "Merge pull request #2814 from jsfb/testutils-consolemock"

This reverts commit 9514861d9397e22d41d59d1e8cdd6de92fa74204, reversing changes made to cdec83732df3ec19fafaceafd8b930129222e4bd.

Paul O’Shannessy committed Jan 15, 2015 at 13:35 UTC 967435b249eac904e8b01b1955fa12053d2950df
2 files changed +11 -74
src/test/ReactTestUtils.js
-60
@@ -309,66 +309,6 @@ var ReactTestUtils = {
309 return new ReactShallowRenderer();
310 },
311
312 - jasmineMatchers: {
313 - /**
314 - * Expect function to perform a console.warn.
315 - * If `expectation` is a number, we expect the function to make `expectation` calls to warn.
316 - * If `expectation` is a string, we expect that string to appear in the warn output.
317 - **/
318 - toWarn: function(expectation) {
319 - var mocks = require('mocks');
320 - var warn = console.warn;
321 - console.warn = mocks.getMockFunction();
322 - try {
323 - this.actual();
324 - var consoleLog = console.warn.mock.calls;
325 - var result = { pass: false };
326 - if (typeof expectation === 'number') {
327 - result.pass = consoleLog.length === expectation;
328 - } else {
329 - // TODO: We may want to additionally handle a javascript regex
330 - for (var i = 0; i < consoleLog.length; i++) {
331 - if (consoleLog[i][0].indexOf(expectation) >= 0) {
332 - result.pass = true;
333 - }
334 - }
335 - }
336 -
337 - this.message = function() {
338 - if (result.pass) {
339 - if (typeof expectation === 'number') {
340 - return 'Expected [' + consoleLog + '].length=' +
341 - consoleLog.length + ' NOT to equal expectation (' +
342 - expectation + ').';
343 - }
344 - if (typeof expectation === 'string') {
345 - return 'Expected [' + consoleLog +
346 - '] NOT to contain expectation (' +
347 - expectation + ').';
348 - }
349 - } else {
350 - if (typeof expectation === 'number') {
351 - return 'Expected [' + consoleLog + '].length=' +
352 - consoleLog.length + ' to equal expectation (' +
353 - expectation + ').';
354 - }
355 - if (typeof expectation === 'string') {
356 - return 'Expected [' + consoleLog +
357 - '] to contain expectation (' +
358 - expectation + ').';
359 - }
360 - }
361 - throw new Error('Assert not reached, unknown expectation type: ' + (typeof expectation));
362 - };
363 -
364 - return result.pass;
365 - }
366 - finally {
367 - console.warn = warn;
368 - }
369 - }
370 - },
371 -
312 Simulate: null,
313 SimulateNative: {}
314 };
src/test/__tests__/ReactTestUtils-test.js
+11 -14
@@ -14,13 +14,23 @@
14 var React;
15 var ReactTestUtils;
16
17 +var mocks;
18 +var warn;
19 +
20 describe('ReactTestUtils', function() {
21
22 beforeEach(function() {
23 + mocks = require('mocks');
24 +
25 React = require('React');
26 ReactTestUtils = require('ReactTestUtils');
27
23 - this.addMatchers(ReactTestUtils.jasmineMatchers);
28 + warn = console.warn;
29 + console.warn = mocks.getMockFunction();
30 + });
31 +
32 + afterEach(function() {
33 + console.warn = warn;
34 });
35
36 it('should have shallow rendering', function() {
@@ -110,17 +120,4 @@ describe('ReactTestUtils', function() {
120 expect(scryResults.length).toBe(0);
121
122 });
113 -
114 - it('expect console warn message success (jasmine integration)', function() {
115 - expect(function(){console.warn('candy');}).toWarn('candy');
116 - expect(function(){console.warn('candy');}).toWarn(1);
117 - });
118 -
119 - it('expect console warn to return true/false (direct invocation)', function() {
120 - var scope = { actual: function(){console.warn('candy');} };
121 - expect((ReactTestUtils.jasmineMatchers.toWarn.bind(scope))('candy')).toBe(true);
122 - expect(ReactTestUtils.jasmineMatchers.toWarn.bind(scope)('ice cream')).toBe(false);
123 - expect(ReactTestUtils.jasmineMatchers.toWarn.bind(scope)(1)).toBe(true);
124 - expect(ReactTestUtils.jasmineMatchers.toWarn.bind(scope)(2)).toBe(false);
125 - });
123 });