diff --git a/src/test/ReactTestUtils.js b/src/test/ReactTestUtils.js index da8968085b6..b2e6eb0b1fe 100644 --- a/src/test/ReactTestUtils.js +++ b/src/test/ReactTestUtils.js @@ -309,66 +309,6 @@ var ReactTestUtils = { return new ReactShallowRenderer(); }, - jasmineMatchers: { - /** - * Expect function to perform a console.warn. - * If `expectation` is a number, we expect the function to make `expectation` calls to warn. - * If `expectation` is a string, we expect that string to appear in the warn output. - **/ - toWarn: function(expectation) { - var mocks = require('mocks'); - var warn = console.warn; - console.warn = mocks.getMockFunction(); - try { - this.actual(); - var consoleLog = console.warn.mock.calls; - var result = { pass: false }; - if (typeof expectation === 'number') { - result.pass = consoleLog.length === expectation; - } else { - // TODO: We may want to additionally handle a javascript regex - for (var i = 0; i < consoleLog.length; i++) { - if (consoleLog[i][0].indexOf(expectation) >= 0) { - result.pass = true; - } - } - } - - this.message = function() { - if (result.pass) { - if (typeof expectation === 'number') { - return 'Expected [' + consoleLog + '].length=' + - consoleLog.length + ' NOT to equal expectation (' + - expectation + ').'; - } - if (typeof expectation === 'string') { - return 'Expected [' + consoleLog + - '] NOT to contain expectation (' + - expectation + ').'; - } - } else { - if (typeof expectation === 'number') { - return 'Expected [' + consoleLog + '].length=' + - consoleLog.length + ' to equal expectation (' + - expectation + ').'; - } - if (typeof expectation === 'string') { - return 'Expected [' + consoleLog + - '] to contain expectation (' + - expectation + ').'; - } - } - throw new Error('Assert not reached, unknown expectation type: ' + (typeof expectation)); - }; - - return result.pass; - } - finally { - console.warn = warn; - } - } - }, - Simulate: null, SimulateNative: {} }; diff --git a/src/test/__tests__/ReactTestUtils-test.js b/src/test/__tests__/ReactTestUtils-test.js index 7f16edc43c0..928d983ed31 100644 --- a/src/test/__tests__/ReactTestUtils-test.js +++ b/src/test/__tests__/ReactTestUtils-test.js @@ -14,13 +14,23 @@ var React; var ReactTestUtils; +var mocks; +var warn; + describe('ReactTestUtils', function() { beforeEach(function() { + mocks = require('mocks'); + React = require('React'); ReactTestUtils = require('ReactTestUtils'); - this.addMatchers(ReactTestUtils.jasmineMatchers); + warn = console.warn; + console.warn = mocks.getMockFunction(); + }); + + afterEach(function() { + console.warn = warn; }); it('should have shallow rendering', function() { @@ -110,17 +120,4 @@ describe('ReactTestUtils', function() { expect(scryResults.length).toBe(0); }); - - it('expect console warn message success (jasmine integration)', function() { - expect(function(){console.warn('candy');}).toWarn('candy'); - expect(function(){console.warn('candy');}).toWarn(1); - }); - - it('expect console warn to return true/false (direct invocation)', function() { - var scope = { actual: function(){console.warn('candy');} }; - expect((ReactTestUtils.jasmineMatchers.toWarn.bind(scope))('candy')).toBe(true); - expect(ReactTestUtils.jasmineMatchers.toWarn.bind(scope)('ice cream')).toBe(false); - expect(ReactTestUtils.jasmineMatchers.toWarn.bind(scope)(1)).toBe(true); - expect(ReactTestUtils.jasmineMatchers.toWarn.bind(scope)(2)).toBe(false); - }); });