From c09899d3127baa0c518a849420b8f623d93aaf8f Mon Sep 17 00:00:00 2001 From: Dmitrii Abramov Date: Fri, 13 May 2016 23:11:30 -0700 Subject: [PATCH] jest-cli@12 --- package.json | 1 - scripts/jest/jest.d.ts | 1 + scripts/jest/test-framework-setup.js | 246 ++++++++++++++++-- src/addons/__tests__/ReactFragment-test.js | 22 +- .../renderSubtreeIntoContainer-test.js | 2 +- src/addons/__tests__/update-test.js | 22 +- .../__tests__/ReactCSSTransitionGroup-test.js | 6 +- .../__tests__/ReactDebugTool-test.js | 30 +-- src/isomorphic/__tests__/ReactPerf-test.js | 12 +- .../children/__tests__/ReactChildren-test.js | 26 +- .../__tests__/ReactContextValidator-test.js | 20 +- .../classic/class/__tests__/ReactBind-test.js | 6 +- .../class/__tests__/ReactBindOptout-test.js | 4 +- .../class/__tests__/ReactClass-test.js | 44 ++-- .../class/__tests__/ReactClassMixin-test.js | 14 +- .../element/__tests__/ReactElement-test.js | 28 +- .../__tests__/ReactElementClone-test.js | 18 +- .../__tests__/ReactElementValidator-test.js | 82 +++--- .../types/__tests__/ReactPropTypes-test.js | 26 +- .../__tests__/ReactClassEquivalence-test.js | 2 +- .../ReactCoffeeScriptClass-test.coffee | 30 +-- .../class/__tests__/ReactES6Class-test.js | 30 +-- .../__tests__/ReactTypeScriptClass-test.ts | 34 +-- .../element/__tests__/ReactJSXElement-test.js | 10 +- .../ReactJSXElementValidator-test.js | 64 ++--- .../dom/__tests__/ReactDOMProduction-test.js | 4 +- .../ReactBrowserEventEmitter-test.js | 10 +- .../dom/client/__tests__/ReactDOM-test.js | 14 +- .../dom/client/__tests__/ReactMount-test.js | 32 +-- .../__tests__/ReactMountDestruction-test.js | 8 +- .../__tests__/ReactRenderDocument-test.js | 8 +- .../dom/client/__tests__/findDOMNode-test.js | 4 +- .../__tests__/SyntheticEvent-test.js | 28 +- .../wrappers/__tests__/ReactDOMInput-test.js | 78 +++--- .../wrappers/__tests__/ReactDOMOption-test.js | 8 +- .../wrappers/__tests__/ReactDOMSelect-test.js | 12 +- .../__tests__/ReactDOMTextarea-test.js | 24 +- .../__tests__/ReactServerRendering-test.js | 6 +- .../__tests__/CSSPropertyOperations-test.js | 26 +- .../__tests__/DOMPropertyOperations-test.js | 4 +- .../dom/shared/__tests__/Danger-test.js | 6 +- .../__tests__/ReactDOMComponent-test.js | 211 ++++++++------- .../__tests__/ReactDOMDebugTool-test.js | 30 +-- .../event/__tests__/EventPluginHub-test.js | 2 +- .../__tests__/EventPluginRegistry-test.js | 12 +- .../__tests__/ReactComponent-test.js | 12 +- .../__tests__/ReactComponentLifeCycle-test.js | 16 +- .../__tests__/ReactCompositeComponent-test.js | 46 ++-- .../__tests__/ReactEmptyComponent-test.js | 48 ++-- .../__tests__/ReactMockedComponent-test.js | 2 +- .../ReactMultiChildReconcile-test.js | 2 +- .../__tests__/ReactMultiChildText-test.js | 6 +- .../__tests__/ReactStatelessComponent-test.js | 24 +- .../reconciler/__tests__/ReactUpdates-test.js | 32 +-- .../utils/__tests__/PooledClass-test.js | 2 +- .../utils/__tests__/Transaction-test.js | 2 +- .../utils/__tests__/accumulateInto-test.js | 2 +- .../__tests__/traverseAllChildren-test.js | 50 ++-- src/test/MetaMatchers.js | 41 +-- src/test/__tests__/MetaMatchers-test.js | 14 +- src/test/__tests__/ReactTestUtils-test.js | 12 +- 61 files changed, 922 insertions(+), 696 deletions(-) diff --git a/package.json b/package.json index 794816695352f..9ab68026204c0 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,6 @@ "scriptPreprocessor": "scripts/jest/preprocessor.js", "setupEnvScriptFile": "scripts/jest/environment.js", "setupTestFrameworkScriptFile": "scripts/jest/test-framework-setup.js", - "testRunner": "jasmine1", "testFileExtensions": [ "coffee", "js", diff --git a/scripts/jest/jest.d.ts b/scripts/jest/jest.d.ts index 31fcc07dfcff9..c3e69596f8043 100644 --- a/scripts/jest/jest.d.ts +++ b/scripts/jest/jest.d.ts @@ -17,6 +17,7 @@ declare function xit(name: string, fn: any): void; interface Expect { not: Expect toThrow(message?: string): void + toThrowError(message?: string): void toBe(value: any): void toEqual(value: any): void toBeFalsy(): void diff --git a/scripts/jest/test-framework-setup.js b/scripts/jest/test-framework-setup.js index 107f6a8d43ac2..5803b916a3943 100644 --- a/scripts/jest/test-framework-setup.js +++ b/scripts/jest/test-framework-setup.js @@ -2,34 +2,238 @@ var env = jasmine.getEnv(); +var callCount = 0; var oldError = console.error; var newError = function() { + callCount++; oldError.apply(this, arguments); - var spec = env.currentSpec; - if (spec) { - var expectationResult = new jasmine.ExpectationResult({ - passed: false, - message: - 'Expected test not to warn. If the warning is expected, mock it ' + - 'out using spyOn(console, \'error\'); and test that the warning ' + - 'occurs.', - }); - spec.addMatcherResult(expectationResult); - } }; + console.error = newError; -// Make sure console.error is set back at the end of each test, or else the -// above logic won't work -afterEach(function() { - // TODO: Catch test cases that call spyOn() but don't inspect the mock - // properly. +env.beforeEach(() => { + callCount = 0; + jasmine.addMatchers({ + toBeReset() { + return { + compare(actual) { + // TODO: Catch test cases that call spyOn() but don't inspect the mock + // properly. + if (actual !== newError && !jasmine.isSpy(actual)) { + return { + pass: false, + message: 'Test did not tear down console.error mock properly.', + }; + } + return {pass: true}; + }, + }; + }, + toNotHaveBeenCalled() { + return { + compare(actual) { + return { + pass: callCount === 0, + message: + 'Expected test not to warn. If the warning is expected, mock ' + + 'it out using spyOn(console, \'error\'); and test that the ' + + 'warning occurs.', + }; + }, + }; + }, + }); +}); +env.afterEach(() => { + expect(console.error).toBeReset(); + expect(console.error).toNotHaveBeenCalled(); +}); + + +// MetaMatchers + +class MetaMatcherReporter { + constructor() { + this._testResults = []; + this._currentSuites = []; + } + + specDone(result) { + this._testResults.push( + this._extractSpecResults(result, this._currentSuites.slice(0)) + ); + } + + suiteStarted(suite) { + this._currentSuites.push(suite.description); + } + + suiteDone() { + this._currentSuites.pop(); + } + + getResults() { + return this._testResults; + } - if (console.error !== newError && !console.error.isSpy) { - var expectationResult = new jasmine.ExpectationResult({ - passed: false, - message: 'Test did not tear down console.error mock properly.', + _extractSpecResults(specResult, currentSuites) { + const results = { + title: 'it ' + specResult.description, + ancestorTitles: currentSuites, + failureMessages: [], + numPassingAsserts: 0, // Jasmine2 only returns an array of failed asserts. + }; + + // specResult.failedExpectations.forEach(failed => { + // let message; + // if (!failed.matcherName) { + // message = this._formatter.formatException(failed.stack); + // } else { + // message = this._formatter.formatMatchFailure(failed); + // } + // results.failureMessages.push(message); + // }); + results.failedExpectations = specResult.failedExpectations; + + return results; + } + + getResultsSummary() { + let numFailingTests = 0; + let numPassingTests = 0; + const testResults = this._testResults; + testResults.forEach(testResult => { + if (testResult.failureMessages.length > 0) { + numFailingTests++; + } else { + numPassingTests++; + } }); - env.currentSpec.addMatcherResult(expectationResult); + return { + numTests: numFailingTests + numPassingTests, + numFailingTests, + numPassingTests, + testResults, + }; } +} + +function getRunnerWithResults(describeFunction) { + if (describeFunction._cachedRunner) { + // Cached result of execution. This is a convenience way to test against + // the same authoritative function multiple times. + return describeFunction._cachedRunner; + } + + var myEnv = new jasmine.Env(); + + var matcherReporter = new MetaMatcherReporter(); + myEnv.addReporter(matcherReporter); + + myEnv.describe('', describeFunction); + myEnv.execute(); + console.error('f'); + var results = matcherReporter.getResultsSummary(); + // console.error(results); + console.error(describeFunction.toString()); + + describeFunction._cachedRunner = results; + return results; +} + +function compareSpec(actual, expected) { + if (actual.numTests !== expected.numTests) { + return ( + 'Expected ' + expected.numTests + ' expects, ' + + 'but got ' + actual.numTests + ':' + + actual.title + ); + } + return null; +} + +function includesDescription(specs, description, startIndex) { + for (var i = startIndex; i < specs.length; i++) { + if (specs[i].title === description) { + return true; + } + } + return false; +} + +function compareSpecs(actualSpecs, expectedSpecs) { + for (var i = 0; i < actualSpecs.length && i < expectedSpecs.length; i++) { + var actual = actualSpecs[i]; + var expected = expectedSpecs[i]; + if (actual.title === expected.title) { + var errorMessage = compareSpec(actual, expected); + if (errorMessage) { + return errorMessage; + } + continue; + } else if (includesDescription(actualSpecs, expected.title, i)) { + return 'Did not expect the spec:' + actualSpecs[i].title; + } else { + return 'Expected an equivalent to:' + expectedSpecs[i].gtitle; + } + } + if (i < actualSpecs.length) { + return 'Did not expect the spec:' + actualSpecs[i].title; + } + if (i < expectedSpecs.length) { + return 'Expected an equivalent to:' + expectedSpecs[i].title; + } + return null; +} + +function compareDescription(a, b) { + if (a.title === b.title) { + return 0; + } + return a.title < b.title ? -1 : 1; +} + +function compareRunners(actual, expected) { + return compareSpecs( + actual.testResults.sort(compareDescription), + expected.testResults.sort(compareDescription) + ); +} + +// env.addReporter(); + +env.beforeEach(() => { + jasmine.addMatchers({ + toEqualSpecsIn(/* util, customEqualityMatcher*/) { + return { + compare(actualDescribeFunction, expectedDescribeFunction) { + if (typeof actualDescribeFunction !== 'function') { + throw Error('toEqualSpecsIn() should be used on a describe function'); + } + if (typeof expectedDescribeFunction !== 'function') { + throw Error('toEqualSpecsIn() should be passed a describe function'); + } + var actual = getRunnerWithResults(actualDescribeFunction); + var expected = getRunnerWithResults(expectedDescribeFunction); + var errorMessage = compareRunners(actual, expected); + // var errorMessage = null; + + console.error(actual); + console.error(expected); + console.error('----') + + if (errorMessage) { + return { + pass: false, + message: errorMessage + 'The specs are equal. Expected them to be different.', + } + }; + + return { + pass: true, + }; + }, + }; + }, + }); }); diff --git a/src/addons/__tests__/ReactFragment-test.js b/src/addons/__tests__/ReactFragment-test.js index 4a1b9775d62a6..2ca0302c22332 100644 --- a/src/addons/__tests__/ReactFragment-test.js +++ b/src/addons/__tests__/ReactFragment-test.js @@ -31,7 +31,7 @@ describe('ReactFragment', function() { }; var element =
{[children]}
; var container = document.createElement('div'); - expect(() => ReactDOM.render(element, container)).toThrow( + expect(() => ReactDOM.render(element, container)).toThrowError( 'Objects are not valid as a React child (found: object with keys ' + '{x, y, z}). If you meant to render a collection of children, use an ' + 'array instead or wrap the object using createFragment(object) from ' + @@ -51,7 +51,7 @@ describe('ReactFragment', function() { } } var container = document.createElement('div'); - expect(() => ReactDOM.render(, container)).toThrow( + expect(() => ReactDOM.render(, container)).toThrowError( 'Objects are not valid as a React child (found: object with keys ' + '{a, b, c}). If you meant to render a collection of children, use an ' + 'array instead or wrap the object using createFragment(object) from ' + @@ -62,7 +62,7 @@ describe('ReactFragment', function() { it('should throw if a plain object looks like an old element', function() { var oldEl = {_isReactElement: true, type: 'span', props: {}}; var container = document.createElement('div'); - expect(() => ReactDOM.render(
{oldEl}
, container)).toThrow( + expect(() => ReactDOM.render(
{oldEl}
, container)).toThrowError( 'Objects are not valid as a React child (found: object with keys ' + '{_isReactElement, type, props}). It looks like you\'re using an ' + 'element created by a different version of React. Make sure to use ' + @@ -75,8 +75,8 @@ describe('ReactFragment', function() { ReactFragment.create({1: , 2: }); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'Child objects should have non-numeric keys so ordering is preserved.' ); }); @@ -84,8 +84,8 @@ describe('ReactFragment', function() { it('should warn if passing null to createFragment', function() { spyOn(console, 'error'); ReactFragment.create(null); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'React.addons.createFragment only accepts a single object.' ); }); @@ -93,8 +93,8 @@ describe('ReactFragment', function() { it('should warn if passing an array to createFragment', function() { spyOn(console, 'error'); ReactFragment.create([]); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'React.addons.createFragment only accepts a single object.' ); }); @@ -102,8 +102,8 @@ describe('ReactFragment', function() { it('should warn if passing a ReactElement to createFragment', function() { spyOn(console, 'error'); ReactFragment.create(
); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'React.addons.createFragment does not accept a ReactElement without a ' + 'wrapper object.' ); diff --git a/src/addons/__tests__/renderSubtreeIntoContainer-test.js b/src/addons/__tests__/renderSubtreeIntoContainer-test.js index de67b7ee47947..7898af3d7fba8 100644 --- a/src/addons/__tests__/renderSubtreeIntoContainer-test.js +++ b/src/addons/__tests__/renderSubtreeIntoContainer-test.js @@ -88,7 +88,7 @@ describe('renderSubtreeIntoContainer', function() { componentDidMount: function() { expect(function() { renderSubtreeIntoContainer(, , portal); - }).toThrow('parentComponentmust be a valid React Component'); + }).toThrowError('parentComponentmust be a valid React Component'); }, }); }); diff --git a/src/addons/__tests__/update-test.js b/src/addons/__tests__/update-test.js index 05a6578ee8976..e2682a70c1527 100644 --- a/src/addons/__tests__/update-test.js +++ b/src/addons/__tests__/update-test.js @@ -25,13 +25,13 @@ describe('update', function() { expect(obj).toEqual([1]); }); it('only pushes an array', function() { - expect(update.bind(null, [], {$push: 7})).toThrow( + expect(update.bind(null, [], {$push: 7})).toThrowError( 'update(): expected spec of $push to be an array; got 7. Did you ' + 'forget to wrap your parameter in an array?' ); }); it('only pushes unto an array', function() { - expect(update.bind(null, 1, {$push: 7})).toThrow( + expect(update.bind(null, 1, {$push: 7})).toThrowError( 'update(): expected target of $push to be an array; got 1.' ); }); @@ -47,13 +47,13 @@ describe('update', function() { expect(obj).toEqual([1]); }); it('only unshifts an array', function() { - expect(update.bind(null, [], {$unshift: 7})).toThrow( + expect(update.bind(null, [], {$unshift: 7})).toThrowError( 'update(): expected spec of $unshift to be an array; got 7. Did you ' + 'forget to wrap your parameter in an array?' ); }); it('only unshifts unto an array', function() { - expect(update.bind(null, 1, {$unshift: 7})).toThrow( + expect(update.bind(null, 1, {$unshift: 7})).toThrowError( 'update(): expected target of $unshift to be an array; got 1.' ); }); @@ -69,17 +69,17 @@ describe('update', function() { expect(obj).toEqual([1, 4, 3]); }); it('only splices an array of arrays', function() { - expect(update.bind(null, [], {$splice: 1})).toThrow( + expect(update.bind(null, [], {$splice: 1})).toThrowError( 'update(): expected spec of $splice to be an array of arrays; got 1. ' + 'Did you forget to wrap your parameters in an array?' ); - expect(update.bind(null, [], {$splice: [1]})).toThrow( + expect(update.bind(null, [], {$splice: [1]})).toThrowError( 'update(): expected spec of $splice to be an array of arrays; got 1. ' + 'Did you forget to wrap your parameters in an array?' ); }); it('only splices unto an array', function() { - expect(update.bind(null, 1, {$splice: 7})).toThrow( + expect(update.bind(null, 1, {$splice: 7})).toThrowError( 'Expected $splice target to be an array; got 1' ); }); @@ -95,12 +95,12 @@ describe('update', function() { expect(obj).toEqual({a: 'b'}); }); it('only merges with an object', function() { - expect(update.bind(null, {}, {$merge: 7})).toThrow( + expect(update.bind(null, {}, {$merge: 7})).toThrowError( 'update(): $merge expects a spec of type \'object\'; got 7' ); }); it('only merges with an object', function() { - expect(update.bind(null, 7, {$merge: {a: 'b'}})).toThrow( + expect(update.bind(null, 7, {$merge: {a: 'b'}})).toThrowError( 'update(): $merge expects a target of type \'object\'; got 7' ); }); @@ -130,7 +130,7 @@ describe('update', function() { expect(obj).toEqual({v: 2}); }); it('only applies a function', function() { - expect(update.bind(null, 2, {$apply: 123})).toThrow( + expect(update.bind(null, 2, {$apply: 123})).toThrowError( 'update(): expected spec of $apply to be a function; got 123.' ); }); @@ -170,7 +170,7 @@ describe('update', function() { }); it('should require a command', function() { - expect(update.bind(null, {a: 'b'}, {a: 'c'})).toThrow( + expect(update.bind(null, {a: 'b'}, {a: 'c'})).toThrowError( 'update(): You provided a key path to update() that did not contain ' + 'one of $push, $unshift, $splice, $set, $merge, $apply. Did you ' + 'forget to include {$set: ...}?' diff --git a/src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js b/src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js index 0bf8c6bb2ff79..5d24d9b05dc59 100644 --- a/src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js +++ b/src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js @@ -45,7 +45,7 @@ describe('ReactCSSTransitionGroup', function() { ); // Warning about the missing transitionLeaveTimeout prop - expect(console.error.argsForCall.length).toBe(1); + expect(console.error.calls.count()).toBe(1); }); it('should not warn if timeouts is zero', function() { @@ -61,7 +61,7 @@ describe('ReactCSSTransitionGroup', function() { container ); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('should clean-up silently after the timeout elapses', function() { @@ -103,7 +103,7 @@ describe('ReactCSSTransitionGroup', function() { } // No warnings - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); // The leaving child has been removed expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(1); diff --git a/src/isomorphic/__tests__/ReactDebugTool-test.js b/src/isomorphic/__tests__/ReactDebugTool-test.js index 889b9097982b5..3f380951acf5b 100644 --- a/src/isomorphic/__tests__/ReactDebugTool-test.js +++ b/src/isomorphic/__tests__/ReactDebugTool-test.js @@ -27,31 +27,31 @@ describe('ReactDebugTool', function() { ReactDebugTool.addDevtool(devtool1); ReactDebugTool.onTestEvent(); - expect(handler1.calls.length).toBe(1); - expect(handler2.calls.length).toBe(0); + expect(handler1.calls.count()).toBe(1); + expect(handler2.calls.count()).toBe(0); ReactDebugTool.onTestEvent(); - expect(handler1.calls.length).toBe(2); - expect(handler2.calls.length).toBe(0); + expect(handler1.calls.count()).toBe(2); + expect(handler2.calls.count()).toBe(0); ReactDebugTool.addDevtool(devtool2); ReactDebugTool.onTestEvent(); - expect(handler1.calls.length).toBe(3); - expect(handler2.calls.length).toBe(1); + expect(handler1.calls.count()).toBe(3); + expect(handler2.calls.count()).toBe(1); ReactDebugTool.onTestEvent(); - expect(handler1.calls.length).toBe(4); - expect(handler2.calls.length).toBe(2); + expect(handler1.calls.count()).toBe(4); + expect(handler2.calls.count()).toBe(2); ReactDebugTool.removeDevtool(devtool1); ReactDebugTool.onTestEvent(); - expect(handler1.calls.length).toBe(4); - expect(handler2.calls.length).toBe(3); + expect(handler1.calls.count()).toBe(4); + expect(handler2.calls.count()).toBe(3); ReactDebugTool.removeDevtool(devtool2); ReactDebugTool.onTestEvent(); - expect(handler1.calls.length).toBe(4); - expect(handler2.calls.length).toBe(3); + expect(handler1.calls.count()).toBe(4); + expect(handler2.calls.count()).toBe(3); }); it('warns once when an error is thrown in devtool', () => { @@ -63,14 +63,14 @@ describe('ReactDebugTool', function() { }); ReactDebugTool.onTestEvent(); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'exception thrown by devtool while handling ' + 'onTestEvent: Hi.' ); ReactDebugTool.onTestEvent(); - expect(console.error.calls.length).toBe(1); + expect(console.error.calls.count()).toBe(1); }); it('returns isProfiling state', () => { diff --git a/src/isomorphic/__tests__/ReactPerf-test.js b/src/isomorphic/__tests__/ReactPerf-test.js index 0a24bb9919d7f..a60750267505f 100644 --- a/src/isomorphic/__tests__/ReactPerf-test.js +++ b/src/isomorphic/__tests__/ReactPerf-test.js @@ -260,28 +260,28 @@ describe('ReactPerf', function() { var measurements = measure(() => {}); spyOn(console, 'error'); ReactPerf.getMeasurementsSummaryMap(measurements); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( '`ReactPerf.getMeasurementsSummaryMap(...)` is deprecated. Use ' + '`ReactPerf.getWasted(...)` instead.' ); ReactPerf.getMeasurementsSummaryMap(measurements); - expect(console.error.calls.length).toBe(1); + expect(console.error.calls.count()).toBe(1); }); it('warns once when using printDOM', function() { var measurements = measure(() => {}); spyOn(console, 'error'); ReactPerf.printDOM(measurements); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( '`ReactPerf.printDOM(...)` is deprecated. Use ' + '`ReactPerf.printOperations(...)` instead.' ); ReactPerf.printDOM(measurements); - expect(console.error.calls.length).toBe(1); + expect(console.error.calls.count()).toBe(1); }); it('returns isRunning state', () => { diff --git a/src/isomorphic/children/__tests__/ReactChildren-test.js b/src/isomorphic/children/__tests__/ReactChildren-test.js index e638c68c1022e..76db6cf31ee94 100644 --- a/src/isomorphic/children/__tests__/ReactChildren-test.js +++ b/src/isomorphic/children/__tests__/ReactChildren-test.js @@ -23,7 +23,7 @@ describe('ReactChildren', function() { }); it('should support identity for simple', function() { - var callback = jasmine.createSpy().andCallFake(function(kid, index) { + var callback = jasmine.createSpy().and.callFake(function(kid, index) { return kid; }); @@ -35,14 +35,14 @@ describe('ReactChildren', function() { var instance =
{simpleKid}
; ReactChildren.forEach(instance.props.children, callback); expect(callback).toHaveBeenCalledWith(simpleKid, 0); - callback.reset(); + callback.calls.reset(); var mappedChildren = ReactChildren.map(instance.props.children, callback); expect(callback).toHaveBeenCalledWith(simpleKid, 0); expect(mappedChildren[0]).toEqual(); }); it('should treat single arrayless child as being in array', function() { - var callback = jasmine.createSpy().andCallFake(function(kid, index) { + var callback = jasmine.createSpy().and.callFake(function(kid, index) { return kid; }); @@ -50,14 +50,14 @@ describe('ReactChildren', function() { var instance =
{simpleKid}
; ReactChildren.forEach(instance.props.children, callback); expect(callback).toHaveBeenCalledWith(simpleKid, 0); - callback.reset(); + callback.calls.reset(); var mappedChildren = ReactChildren.map(instance.props.children, callback); expect(callback).toHaveBeenCalledWith(simpleKid, 0); expect(mappedChildren[0]).toEqual(); }); it('should treat single child in array as expected', function() { - var callback = jasmine.createSpy().andCallFake(function(kid, index) { + var callback = jasmine.createSpy().and.callFake(function(kid, index) { return kid; }); @@ -65,7 +65,7 @@ describe('ReactChildren', function() { var instance =
{[simpleKid]}
; ReactChildren.forEach(instance.props.children, callback); expect(callback).toHaveBeenCalledWith(simpleKid, 0); - callback.reset(); + callback.calls.reset(); var mappedChildren = ReactChildren.map(instance.props.children, callback); expect(callback).toHaveBeenCalledWith(simpleKid, 0); expect(mappedChildren[0]).toEqual(); @@ -124,7 +124,7 @@ describe('ReactChildren', function() { , // Map from null to something.
, ]; - var callback = jasmine.createSpy().andCallFake(function(kid, index) { + var callback = jasmine.createSpy().and.callFake(function(kid, index) { return mapped[index]; }); @@ -144,11 +144,11 @@ describe('ReactChildren', function() { expect(callback).toHaveBeenCalledWith(two, 2); expect(callback).toHaveBeenCalledWith(three, 3); expect(callback).toHaveBeenCalledWith(four, 4); - callback.reset(); + callback.calls.reset(); var mappedChildren = ReactChildren.map(instance.props.children, callback); - expect(callback.calls.length).toBe(5); + expect(callback.calls.count()).toBe(5); expect(ReactChildren.count(mappedChildren)).toBe(4); // Keys default to indices. expect([ @@ -190,7 +190,7 @@ describe('ReactChildren', function() { var fourMapped =
; var fiveMapped =
; - var callback = jasmine.createSpy().andCallFake(function(kid, index) { + var callback = jasmine.createSpy().and.callFake(function(kid, index) { return index === 0 ? zeroMapped : index === 1 ? twoMapped : index === 2 ? fourMapped : fiveMapped; @@ -216,15 +216,15 @@ describe('ReactChildren', function() { ]); ReactChildren.forEach(instance.props.children, callback); - expect(callback.calls.length).toBe(4); + expect(callback.calls.count()).toBe(4); expect(callback).toHaveBeenCalledWith(frag[0], 0); expect(callback).toHaveBeenCalledWith(frag[1], 1); expect(callback).toHaveBeenCalledWith(frag[2], 2); expect(callback).toHaveBeenCalledWith(frag[3], 3); - callback.reset(); + callback.calls.reset(); var mappedChildren = ReactChildren.map(instance.props.children, callback); - expect(callback.calls.length).toBe(4); + expect(callback.calls.count()).toBe(4); expect(callback).toHaveBeenCalledWith(frag[0], 0); expect(callback).toHaveBeenCalledWith(frag[1], 1); expect(callback).toHaveBeenCalledWith(frag[2], 2); diff --git a/src/isomorphic/classic/__tests__/ReactContextValidator-test.js b/src/isomorphic/classic/__tests__/ReactContextValidator-test.js index cc09080f0cc96..43490fc4c72e9 100644 --- a/src/isomorphic/classic/__tests__/ReactContextValidator-test.js +++ b/src/isomorphic/classic/__tests__/ReactContextValidator-test.js @@ -145,8 +145,8 @@ describe('ReactContextValidator', function() { ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Failed Context Types: ' + 'Required context `foo` was not specified in `Component`.' ); @@ -172,7 +172,7 @@ describe('ReactContextValidator', function() { ); // Previous call should not error - expect(console.error.argsForCall.length).toBe(1); + expect(console.error.calls.count()).toBe(1); var ComponentInFooNumberContext = React.createClass({ childContextTypes: { @@ -192,8 +192,8 @@ describe('ReactContextValidator', function() { ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall.length).toBe(2); - expect(console.error.argsForCall[1][0]).toBe( + expect(console.error.calls.count()).toBe(2); + expect(console.error.calls.argsFor(1)[0]).toBe( 'Warning: Failed Context Types: ' + 'Invalid context `foo` of type `number` supplied ' + 'to `Component`, expected `string`.' + @@ -220,16 +220,16 @@ describe('ReactContextValidator', function() { }); ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Failed Context Types: ' + 'Required child context `foo` was not specified in `Component`.' ); ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall.length).toBe(2); - expect(console.error.argsForCall[1][0]).toBe( + expect(console.error.calls.count()).toBe(2); + expect(console.error.calls.argsFor(1)[0]).toBe( 'Warning: Failed Context Types: ' + 'Invalid child context `foo` of type `number` ' + 'supplied to `Component`, expected `string`.' @@ -244,7 +244,7 @@ describe('ReactContextValidator', function() { ); // Previous calls should not log errors - expect(console.error.argsForCall.length).toBe(2); + expect(console.error.calls.count()).toBe(2); }); }); diff --git a/src/isomorphic/classic/class/__tests__/ReactBind-test.js b/src/isomorphic/classic/class/__tests__/ReactBind-test.js index bbf9d0c7da41c..5d1f4eda94a6b 100644 --- a/src/isomorphic/classic/class/__tests__/ReactBind-test.js +++ b/src/isomorphic/classic/class/__tests__/ReactBind-test.js @@ -132,8 +132,8 @@ describe('autobinding', function() { ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: bind(): You are binding a component method to the component. ' + 'React does this for you automatically in a high-performance ' + 'way, so you can safely remove this call. See TestBindComponent' @@ -160,7 +160,7 @@ describe('autobinding', function() { ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); }); diff --git a/src/isomorphic/classic/class/__tests__/ReactBindOptout-test.js b/src/isomorphic/classic/class/__tests__/ReactBindOptout-test.js index 54d3c11f5c970..39ef8f9770540 100644 --- a/src/isomorphic/classic/class/__tests__/ReactBindOptout-test.js +++ b/src/isomorphic/classic/class/__tests__/ReactBindOptout-test.js @@ -203,7 +203,7 @@ describe('autobind optout', function() { ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('does not warn if you pass an manually bound method to setState', function() { @@ -227,7 +227,7 @@ describe('autobind optout', function() { ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); }); diff --git a/src/isomorphic/classic/class/__tests__/ReactClass-test.js b/src/isomorphic/classic/class/__tests__/ReactClass-test.js index 9a5587f7b7dd0..b55c1079daa9d 100644 --- a/src/isomorphic/classic/class/__tests__/ReactClass-test.js +++ b/src/isomorphic/classic/class/__tests__/ReactClass-test.js @@ -26,7 +26,7 @@ describe('ReactClass-spec', function() { it('should throw when `render` is not specified', function() { expect(function() { React.createClass({}); - }).toThrow( + }).toThrowError( 'createClass(...): Class specification must implement a `render` method.' ); }); @@ -69,8 +69,8 @@ describe('ReactClass-spec', function() { return {this.props.prop}; }, }); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Component: prop type `prop` is invalid; ' + 'it must be a function, usually from React.PropTypes.' ); @@ -87,8 +87,8 @@ describe('ReactClass-spec', function() { return {this.props.prop}; }, }); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Component: context type `prop` is invalid; ' + 'it must be a function, usually from React.PropTypes.' ); @@ -105,8 +105,8 @@ describe('ReactClass-spec', function() { return {this.props.prop}; }, }); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Component: child context type `prop` is invalid; ' + 'it must be a function, usually from React.PropTypes.' ); @@ -123,8 +123,8 @@ describe('ReactClass-spec', function() { return
; }, }); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: A component has a method called componentShouldUpdate(). Did you ' + 'mean shouldComponentUpdate()? The name is phrased as a question ' + 'because the function is expected to return a value.' @@ -139,8 +139,8 @@ describe('ReactClass-spec', function() { return
; }, }); - expect(console.error.argsForCall.length).toBe(2); - expect(console.error.argsForCall[1][0]).toBe( + expect(console.error.calls.count()).toBe(2); + expect(console.error.calls.argsFor(1)[0]).toBe( 'Warning: NamedComponent has a method called componentShouldUpdate(). Did you ' + 'mean shouldComponentUpdate()? The name is phrased as a question ' + 'because the function is expected to return a value.' @@ -157,8 +157,8 @@ describe('ReactClass-spec', function() { return
; }, }); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: A component has a method called componentWillRecieveProps(). Did you ' + 'mean componentWillReceiveProps()?' ); @@ -179,7 +179,7 @@ describe('ReactClass-spec', function() { return ; }, }); - }).toThrow( + }).toThrowError( 'ReactClass: You are attempting to define a reserved property, ' + '`getDefaultProps`, that shouldn\'t be on the "statics" key. Define ' + 'it as an instance property instead; it will still be accessible on ' + @@ -206,20 +206,20 @@ describe('ReactClass-spec', function() { return
; }, }); - expect(console.error.argsForCall.length).toBe(4); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(4); + expect(console.error.calls.argsFor(0)[0]).toBe( 'createClass(...): `mixins` is now a static property and should ' + 'be defined inside "statics".' ); - expect(console.error.argsForCall[1][0]).toBe( + expect(console.error.calls.argsFor(1)[0]).toBe( 'createClass(...): `propTypes` is now a static property and should ' + 'be defined inside "statics".' ); - expect(console.error.argsForCall[2][0]).toBe( + expect(console.error.calls.argsFor(2)[0]).toBe( 'createClass(...): `contextTypes` is now a static property and ' + 'should be defined inside "statics".' ); - expect(console.error.argsForCall[3][0]).toBe( + expect(console.error.calls.argsFor(3)[0]).toBe( 'createClass(...): `childContextTypes` is now a static property and ' + 'should be defined inside "statics".' ); @@ -314,7 +314,7 @@ describe('ReactClass-spec', function() { var instance = ; expect(function() { instance = ReactTestUtils.renderIntoDocument(instance); - }).toThrow( + }).toThrowError( 'Component.getInitialState(): must return an object or null' ); }); @@ -343,8 +343,8 @@ describe('ReactClass-spec', function() { }); expect(() => Component()).toThrow(); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Something is calling a React component directly. Use a ' + 'factory or JSX instead. See: https://fb.me/react-legacyfactory' ); diff --git a/src/isomorphic/classic/class/__tests__/ReactClassMixin-test.js b/src/isomorphic/classic/class/__tests__/ReactClassMixin-test.js index f32af1e0460a2..20a140236ddcb 100644 --- a/src/isomorphic/classic/class/__tests__/ReactClassMixin-test.js +++ b/src/isomorphic/classic/class/__tests__/ReactClassMixin-test.js @@ -155,12 +155,12 @@ describe('ReactClass-mixin', function() { it('should override mixin prop types with class prop types', function() { // Sanity check... - expect(componentPropValidator).toNotBe(mixinPropValidator); + expect(componentPropValidator).not.toBe(mixinPropValidator); // Actually check... expect(TestComponentWithPropTypes.propTypes) .toBeDefined(); expect(TestComponentWithPropTypes.propTypes.value) - .toNotBe(mixinPropValidator); + .not.toBe(mixinPropValidator); expect(TestComponentWithPropTypes.propTypes.value) .toBe(componentPropValidator); }); @@ -205,7 +205,7 @@ describe('ReactClass-mixin', function() { var instance = ; expect(function() { instance = ReactTestUtils.renderIntoDocument(instance); - }).toThrow( + }).toThrowError( 'mergeIntoWithNoDuplicateKeys(): Tried to merge two objects with the ' + 'same key: `x`. This conflict may be due to a mixin; in particular, ' + 'this may be caused by two getInitialState() or getDefaultProps() ' + @@ -276,7 +276,7 @@ describe('ReactClass-mixin', function() { return ; }, }); - }).toThrow( + }).toThrowError( 'ReactClass: You are attempting to define `abc` on your component more ' + 'than once. This conflict may be due to a mixin.' ); @@ -304,7 +304,7 @@ describe('ReactClass-mixin', function() { return ; }, }); - }).toThrow( + }).toThrowError( 'ReactClass: You are attempting to define `abc` on your component ' + 'more than once. This conflict may be due to a mixin.' ); @@ -319,7 +319,7 @@ describe('ReactClass-mixin', function() { return ; }, }); - }).toThrow( + }).toThrowError( 'ReactClass: You\'re attempting to use a component as a mixin. ' + 'Instead, just use a regular object.' ); @@ -340,7 +340,7 @@ describe('ReactClass-mixin', function() { return ; }, }); - }).toThrow( + }).toThrowError( 'ReactClass: You\'re attempting to use a component class or function ' + 'as a mixin. Instead, just use a regular object.' ); diff --git a/src/isomorphic/classic/element/__tests__/ReactElement-test.js b/src/isomorphic/classic/element/__tests__/ReactElement-test.js index 8b3900db9f651..6ce828f5ed7e1 100644 --- a/src/isomorphic/classic/element/__tests__/ReactElement-test.js +++ b/src/isomorphic/classic/element/__tests__/ReactElement-test.js @@ -76,10 +76,10 @@ describe('ReactElement', function() { ); }, }); - expect(console.error.calls.length).toBe(0); + expect(console.error.calls.count()).toBe(0); ReactDOM.render(, container); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'Child: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + @@ -104,10 +104,10 @@ describe('ReactElement', function() { ); }, }); - expect(console.error.calls.length).toBe(0); + expect(console.error.calls.count()).toBe(0); ReactDOM.render(, container); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'Child: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + @@ -143,8 +143,8 @@ describe('ReactElement', function() { React.createElement('div', {foo: 1}); expect(console.error).not.toHaveBeenCalled(); React.createElement('div', Object.create({foo: 1})); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'React.createElement(...): Expected props argument to be a plain object. ' + 'Properties defined in its prototype chain will be ignored.' ); @@ -202,7 +202,7 @@ describe('ReactElement', function() { children: 'text', }, a); expect(element.props.children).toBe(a); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('does not override children if no rest args are provided', function() { @@ -211,7 +211,7 @@ describe('ReactElement', function() { children: 'text', }); expect(element.props.children).toBe('text'); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('overrides children if null is provided as an argument', function() { @@ -220,7 +220,7 @@ describe('ReactElement', function() { children: 'text', }, null); expect(element.props.children).toBe(null); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('merges rest arguments onto the children prop in an array', function() { @@ -230,7 +230,7 @@ describe('ReactElement', function() { var c = 3; var element = React.createFactory(ComponentClass)(null, a, b, c); expect(element.props.children).toEqual([1, 2, 3]); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); // NOTE: We're explicitly not using JSX here. This is intended to test @@ -254,7 +254,7 @@ describe('ReactElement', function() { var element = React.createElement(StaticMethodComponentClass); expect(element.type.someStaticMethod()).toBe('someReturnValue'); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); // NOTE: We're explicitly not using JSX here. This is intended to test @@ -422,7 +422,7 @@ describe('ReactElement', function() { }); var test = ReactTestUtils.renderIntoDocument(); expect(test.props.value).toBeNaN(); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); // NOTE: We're explicitly not using JSX here. This is intended to test diff --git a/src/isomorphic/classic/element/__tests__/ReactElementClone-test.js b/src/isomorphic/classic/element/__tests__/ReactElementClone-test.js index 20b4089726433..1cbdeb4a89429 100644 --- a/src/isomorphic/classic/element/__tests__/ReactElementClone-test.js +++ b/src/isomorphic/classic/element/__tests__/ReactElementClone-test.js @@ -71,8 +71,8 @@ describe('ReactElementClone', function() { React.cloneElement('div', {foo: 1}); expect(console.error).not.toHaveBeenCalled(); React.cloneElement('div', Object.create({foo: 1})); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'React.cloneElement(...): Expected props argument to be a plain object. ' + 'Properties defined in its prototype chain will be ignored.' ); @@ -213,8 +213,8 @@ describe('ReactElementClone', function() { React.cloneElement(
, null, [
,
]); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'Each child in an array or iterator should have a unique "key" prop.' ); }); @@ -224,7 +224,7 @@ describe('ReactElementClone', function() { React.cloneElement(
, null, [
,
]); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('does not warn when the element is directly in rest args', function() { @@ -232,7 +232,7 @@ describe('ReactElementClone', function() { React.cloneElement(
, null,
,
); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('does not warn when the array contains a non-element', function() { @@ -240,7 +240,7 @@ describe('ReactElementClone', function() { React.cloneElement(
, null, [{}, {}]); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('should check declared prop types after clone', function() { @@ -267,8 +267,8 @@ describe('ReactElementClone', function() { }, }); ReactTestUtils.renderIntoDocument(React.createElement(GrandParent)); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Failed propType: ' + 'Invalid prop `color` of type `number` supplied to `Component`, ' + 'expected `string`. Check the render method of `Parent`.' diff --git a/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js b/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js index 3cdcd48e5bb9d..650b970ca4e9d 100644 --- a/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js +++ b/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js @@ -40,8 +40,8 @@ describe('ReactElementValidator', function() { Component(null, [Component(), Component()]); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'Each child in an array or iterator should have a unique "key" prop.' ); }); @@ -70,8 +70,8 @@ describe('ReactElementValidator', function() { React.createElement(ComponentWrapper) ); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'Each child in an array or iterator should have a unique "key" prop. ' + 'Check the render method of `InnerClass`. ' + 'It was passed a child from ComponentWrapper. ' @@ -94,8 +94,8 @@ describe('ReactElementValidator', function() { ]; ReactTestUtils.renderIntoDocument({divs}); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Each child in an array or iterator should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for more information.' ); @@ -110,8 +110,8 @@ describe('ReactElementValidator', function() { ]; ReactTestUtils.renderIntoDocument(
{divs}
); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Each child in an array or iterator should have a unique ' + '"key" prop. Check the top-level render call using
. See ' + 'https://fb.me/react-warning-keys for more information.' @@ -139,7 +139,7 @@ describe('ReactElementValidator', function() { ); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('warns for keys for iterables of elements in rest args', function() { @@ -160,8 +160,8 @@ describe('ReactElementValidator', function() { Component(null, iterable); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'Each child in an array or iterator should have a unique "key" prop.' ); }); @@ -172,7 +172,7 @@ describe('ReactElementValidator', function() { Component(null, [Component({key: '#1'}), Component({key: '#2'})]); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('does not warns for iterable elements with keys', function() { @@ -196,7 +196,7 @@ describe('ReactElementValidator', function() { Component(null, iterable); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('does not warn when the element is directly in rest args', function() { @@ -205,7 +205,7 @@ describe('ReactElementValidator', function() { Component(null, Component(), Component()); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('does not warn when the array contains a non-element', function() { @@ -214,7 +214,7 @@ describe('ReactElementValidator', function() { Component(null, [{}, {}]); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); // TODO: These warnings currently come from the composite component, but @@ -239,7 +239,7 @@ describe('ReactElementValidator', function() { }, }); ReactTestUtils.renderIntoDocument(React.createElement(ParentComp)); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Failed propType: ' + 'Invalid prop `color` of type `number` supplied to `MyComp`, ' + 'expected `string`. Check the render method of `ParentComp`.' @@ -252,29 +252,29 @@ describe('ReactElementValidator', function() { React.createElement(null); React.createElement(true); React.createElement(123); - expect(console.error.calls.length).toBe(4); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(4); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: React.createElement: type should not be null, undefined, ' + 'boolean, or number. It should be a string (for DOM elements) or a ' + 'ReactClass (for composite components).' ); - expect(console.error.argsForCall[1][0]).toBe( + expect(console.error.calls.argsFor(1)[0]).toBe( 'Warning: React.createElement: type should not be null, undefined, ' + 'boolean, or number. It should be a string (for DOM elements) or a ' + 'ReactClass (for composite components).' ); - expect(console.error.argsForCall[2][0]).toBe( + expect(console.error.calls.argsFor(2)[0]).toBe( 'Warning: React.createElement: type should not be null, undefined, ' + 'boolean, or number. It should be a string (for DOM elements) or a ' + 'ReactClass (for composite components).' ); - expect(console.error.argsForCall[3][0]).toBe( + expect(console.error.calls.argsFor(3)[0]).toBe( 'Warning: React.createElement: type should not be null, undefined, ' + 'boolean, or number. It should be a string (for DOM elements) or a ' + 'ReactClass (for composite components).' ); React.createElement('div'); - expect(console.error.calls.length).toBe(4); + expect(console.error.calls.count()).toBe(4); }); it('includes the owner name when passing null, undefined, boolean, or number', function() { @@ -286,13 +286,13 @@ describe('ReactElementValidator', function() { }); expect(function() { ReactTestUtils.renderIntoDocument(React.createElement(ParentComp)); - }).toThrow( + }).toThrowError( 'Element type is invalid: expected a string (for built-in components) ' + 'or a class/function (for composite components) but got: null. Check ' + 'the render method of `ParentComp`.' ); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: React.createElement: type should not be null, undefined, ' + 'boolean, or number. It should be a string (for DOM elements) or a ' + 'ReactClass (for composite components). Check the render method of ' + @@ -315,8 +315,8 @@ describe('ReactElementValidator', function() { ReactTestUtils.renderIntoDocument(React.createElement(Component)); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Failed propType: ' + 'Required prop `prop` was not specified in `Component`.' ); @@ -339,8 +339,8 @@ describe('ReactElementValidator', function() { React.createElement(Component, {prop:null}) ); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Failed propType: ' + 'Required prop `prop` was not specified in `Component`.' ); @@ -365,13 +365,13 @@ describe('ReactElementValidator', function() { React.createElement(Component, {prop: 42}) ); - expect(console.error.calls.length).toBe(2); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(2); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Failed propType: ' + 'Required prop `prop` was not specified in `Component`.' ); - expect(console.error.argsForCall[1][0]).toBe( + expect(console.error.calls.argsFor(1)[0]).toBe( 'Warning: Failed propType: ' + 'Invalid prop `prop` of type `number` supplied to ' + '`Component`, expected `string`.' @@ -382,7 +382,7 @@ describe('ReactElementValidator', function() { ); // Should not error for strings - expect(console.error.calls.length).toBe(2); + expect(console.error.calls.count()).toBe(2); }); it('should warn if a PropType creator is used as a PropType', function() { @@ -401,8 +401,8 @@ describe('ReactElementValidator', function() { React.createElement(Component, {myProp: {value: 'hi'}}) ); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Component: type specification of prop `myProp` is invalid; ' + 'the type checker function must return `null` or an `Error` but ' + 'returned a function. You may have forgotten to pass an argument to ' + @@ -420,14 +420,14 @@ describe('ReactElementValidator', function() { }); var TestFactory = React.createFactory(TestComponent); expect(TestFactory.type).toBe(TestComponent); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Factory.type is deprecated. Access the class directly before ' + 'passing it to createFactory.' ); // Warn once, not again expect(TestFactory.type).toBe(TestComponent); - expect(console.error.argsForCall.length).toBe(1); + expect(console.error.calls.count()).toBe(1); }); it('does not warn when using DOM node as children', function() { @@ -444,7 +444,7 @@ describe('ReactElementValidator', function() { var node = document.createElement('div'); // This shouldn't cause a stack overflow or any other problems (#3883) ReactTestUtils.renderIntoDocument({node}); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('should not enumerate enumerable numbers (#4776)', function() { @@ -487,8 +487,8 @@ describe('ReactElementValidator', function() { spyOn(console, 'error'); var Foo = undefined; void {[
]}; - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: React.createElement: type should not be null, undefined, ' + 'boolean, or number. It should be a string (for DOM elements) or a ' + 'ReactClass (for composite components).' diff --git a/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js b/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js index ea8d54035a113..d1014130b04aa 100644 --- a/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js +++ b/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js @@ -271,7 +271,7 @@ describe('ReactPropTypes', function() { var instance = } />; instance = ReactTestUtils.renderIntoDocument(instance); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('should warn when passing no label and isRequired is set', () => { @@ -280,7 +280,7 @@ describe('ReactPropTypes', function() { var instance = ; instance = ReactTestUtils.renderIntoDocument(instance); - expect(console.error.argsForCall.length).toBe(1); + expect(console.error.calls.count()).toBe(1); }); it('should be implicitly optional and not warn without values', function() { @@ -421,7 +421,7 @@ describe('ReactPropTypes', function() { k4: null, k5: undefined, })); - expect(console.error.calls).toEqual([]); + expect(console.error.calls.count()).toBe(0); }); it('should not warn for iterables', function() { @@ -849,9 +849,9 @@ describe('ReactPropTypes', function() { var instance = ; instance = ReactTestUtils.renderIntoDocument(instance); - expect(spy.argsForCall.length).toBe(2); // temp double validation - expect(spy.argsForCall[0][1]).toBe('num'); - expect(spy.argsForCall[0][2]).toBe('Component'); + expect(spy.calls.count()).toBe(2); // temp double validation + expect(spy.calls.argsFor(0)[1]).toBe('num'); + expect(spy.calls.argsFor(0)[2]).toBe('Component'); }); it('should have been called even if the prop is not present', function() { @@ -867,13 +867,12 @@ describe('ReactPropTypes', function() { var instance = ; instance = ReactTestUtils.renderIntoDocument(instance); - expect(spy.argsForCall.length).toBe(2); // temp double validation + expect(spy.calls.count()).toBe(2); // temp double validation }); it('should have received the validator\'s return value', function() { spyOn(console, 'error'); - - var spy = jasmine.createSpy().andCallFake( + var spy = jasmine.createSpy().and.callFake( function(props, propName, componentName) { if (props[propName] !== 5) { return new Error('num must be 5!'); @@ -890,8 +889,8 @@ describe('ReactPropTypes', function() { var instance = ; instance = ReactTestUtils.renderIntoDocument(instance); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Failed propType: num must be 5!' ); }); @@ -899,8 +898,7 @@ describe('ReactPropTypes', function() { it('should not warn if the validator returned null', function() { spyOn(console, 'error'); - - var spy = jasmine.createSpy().andCallFake( + var spy = jasmine.createSpy().and.callFake( function(props, propName, componentName) { return null; } @@ -915,7 +913,7 @@ describe('ReactPropTypes', function() { var instance = ; instance = ReactTestUtils.renderIntoDocument(instance); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); } ); }); diff --git a/src/isomorphic/modern/class/__tests__/ReactClassEquivalence-test.js b/src/isomorphic/modern/class/__tests__/ReactClassEquivalence-test.js index 36cf5c75ce6b0..6aea2590cb742 100644 --- a/src/isomorphic/modern/class/__tests__/ReactClassEquivalence-test.js +++ b/src/isomorphic/modern/class/__tests__/ReactClassEquivalence-test.js @@ -16,7 +16,7 @@ var MetaMatchers = require('MetaMatchers'); describe('ReactClassEquivalence', function() { beforeEach(function() { - this.addMatchers(MetaMatchers); + jasmine.addMatchers(MetaMatchers); }); var es6 = () => require('./ReactES6Class-test.js'); diff --git a/src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee b/src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee index e7b1f574c579a..88d12af471387 100644 --- a/src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee +++ b/src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee @@ -51,8 +51,8 @@ describe 'ReactCoffeeScriptClass', -> expect(-> ReactDOM.render React.createElement(Foo), container ).toThrow() - expect(console.error.calls.length).toBe(1) - expect(console.error.argsForCall[0][0]).toContain('No `render` method found on the returned component instance') + expect(console.error.calls.count()).toBe(1) + expect(console.error.calls.argsFor(0)[0]).toContain('No `render` method found on the returned component instance') it 'renders a simple stateless component with prop', -> class Foo extends React.Component @@ -153,7 +153,7 @@ describe 'ReactCoffeeScriptClass', -> expect(-> test React.createElement(Foo), 'span', '' - ).toThrow( + ).toThrowError( 'Foo.state: must be set to an object or null' ) @@ -292,17 +292,17 @@ describe 'ReactCoffeeScriptClass', -> test React.createElement(Foo), 'SPAN', 'foo' expect(getInitialStateWasCalled).toBe false expect(getDefaultPropsWasCalled).toBe false - expect(console.error.calls.length).toBe 4 - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe 4 + expect(console.error.calls.argsFor(0)[0]).toContain( 'getInitialState was defined on Foo, a plain JavaScript class.' ) - expect(console.error.argsForCall[1][0]).toContain( + expect(console.error.calls.argsFor(1)[0]).toContain( 'getDefaultProps was defined on Foo, a plain JavaScript class.' ) - expect(console.error.argsForCall[2][0]).toContain( + expect(console.error.calls.argsFor(2)[0]).toContain( 'propTypes was defined as an instance property on Foo.' ) - expect(console.error.argsForCall[3][0]).toContain( + expect(console.error.calls.argsFor(3)[0]).toContain( 'contextTypes was defined as an instance property on Foo.' ) @@ -317,8 +317,8 @@ describe 'ReactCoffeeScriptClass', -> className: 'foo' test React.createElement(NamedComponent), 'SPAN', 'foo' - expect(console.error.calls.length).toBe 1 - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe 1 + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: NamedComponent has a method called componentShouldUpdate(). Did you mean shouldComponentUpdate()? The name is phrased as a question because the function is expected to return a value.' @@ -335,8 +335,8 @@ describe 'ReactCoffeeScriptClass', -> className: 'foo' test React.createElement(NamedComponent), 'SPAN', 'foo' - expect(console.error.calls.length).toBe 1 - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe 1 + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: NamedComponent has a method called componentWillRecieveProps(). Did you mean componentWillReceiveProps()?' ) @@ -349,11 +349,11 @@ describe 'ReactCoffeeScriptClass', -> expect(-> instance.isMounted()).toThrow() expect(-> instance.setProps name: 'bar').toThrow() expect(-> instance.replaceProps name: 'bar').toThrow() - expect(console.error.calls.length).toBe 2 - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe 2 + expect(console.error.calls.argsFor(0)[0]).toContain( 'replaceState(...) is deprecated in plain JavaScript React classes' ) - expect(console.error.argsForCall[1][0]).toContain( + expect(console.error.calls.argsFor(1)[0]).toContain( 'isMounted(...) is deprecated in plain JavaScript React classes' ) diff --git a/src/isomorphic/modern/class/__tests__/ReactES6Class-test.js b/src/isomorphic/modern/class/__tests__/ReactES6Class-test.js index 17a2414c53d22..de2a5e591c6a4 100644 --- a/src/isomorphic/modern/class/__tests__/ReactES6Class-test.js +++ b/src/isomorphic/modern/class/__tests__/ReactES6Class-test.js @@ -61,8 +61,8 @@ describe('ReactES6Class', function() { class Foo extends React.Component { } expect(() => ReactDOM.render(, container)).toThrow(); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Foo(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.' ); @@ -173,7 +173,7 @@ describe('ReactES6Class', function() { return ; } } - expect(() => test(, 'span', '')).toThrow( + expect(() => test(, 'span', '')).toThrowError( 'Foo.state: must be set to an object or null' ); }); @@ -339,17 +339,17 @@ describe('ReactES6Class', function() { test(, 'SPAN', 'foo'); expect(getInitialStateWasCalled).toBe(false); expect(getDefaultPropsWasCalled).toBe(false); - expect(console.error.calls.length).toBe(4); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(4); + expect(console.error.calls.argsFor(0)[0]).toContain( 'getInitialState was defined on Foo, a plain JavaScript class.' ); - expect(console.error.argsForCall[1][0]).toContain( + expect(console.error.calls.argsFor(1)[0]).toContain( 'getDefaultProps was defined on Foo, a plain JavaScript class.' ); - expect(console.error.argsForCall[2][0]).toContain( + expect(console.error.calls.argsFor(2)[0]).toContain( 'propTypes was defined as an instance property on Foo.' ); - expect(console.error.argsForCall[3][0]).toContain( + expect(console.error.calls.argsFor(3)[0]).toContain( 'contextTypes was defined as an instance property on Foo.' ); }); @@ -367,8 +367,8 @@ describe('ReactES6Class', function() { } test(, 'SPAN', 'foo'); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: ' + 'NamedComponent has a method called componentShouldUpdate(). Did you ' + 'mean shouldComponentUpdate()? The name is phrased as a question ' + @@ -389,8 +389,8 @@ describe('ReactES6Class', function() { } test(, 'SPAN', 'foo'); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: ' + 'NamedComponent has a method called componentWillRecieveProps(). Did ' + 'you mean componentWillReceiveProps()?' @@ -404,11 +404,11 @@ describe('ReactES6Class', function() { expect(() => instance.isMounted()).toThrow(); expect(() => instance.setProps({name: 'bar'})).toThrow(); expect(() => instance.replaceProps({name: 'bar'})).toThrow(); - expect(console.error.calls.length).toBe(2); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(2); + expect(console.error.calls.argsFor(0)[0]).toContain( 'replaceState(...) is deprecated in plain JavaScript React classes' ); - expect(console.error.argsForCall[1][0]).toContain( + expect(console.error.calls.argsFor(1)[0]).toContain( 'isMounted(...) is deprecated in plain JavaScript React classes' ); }); diff --git a/src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts b/src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts index 0078265bcb25c..e43651e714326 100644 --- a/src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts +++ b/src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts @@ -316,8 +316,8 @@ describe('ReactTypeScriptClass', function() { expect(() => ReactDOM.render(React.createElement(Empty), container)).toThrow(); - expect((console.error).argsForCall.length).toBe(1); - expect((console.error).argsForCall[0][0]).toBe( + expect((console.error).calls.count()).toBe(1); + expect((console.error).calls.argsFor(0)[0]).toBe( 'Warning: Empty(...): No `render` method found on the returned ' + 'component instance: you may have forgotten to define `render`.' ); @@ -358,15 +358,15 @@ describe('ReactTypeScriptClass', function() { it('should throw with non-object in the initial state property', function() { expect(() => test(React.createElement(ArrayState), 'span', '')) - .toThrow( + .toThrowError( 'ArrayState.state: must be set to an object or null' ); expect(() => test(React.createElement(StringState), 'span', '')) - .toThrow( + .toThrowError( 'StringState.state: must be set to an object or null' ); expect(() => test(React.createElement(NumberState), 'span', '')) - .toThrow( + .toThrowError( 'NumberState.state: must be set to an object or null' ); }); @@ -434,19 +434,19 @@ describe('ReactTypeScriptClass', function() { test(React.createElement(ClassicProperties), 'SPAN', 'foo'); expect(getInitialStateWasCalled).toBe(false); expect(getDefaultPropsWasCalled).toBe(false); - expect((console.error).argsForCall.length).toBe(4); - expect((console.error).argsForCall[0][0]).toContain( + expect((console.error).calls.count()).toBe(4); + expect((console.error).calls.argsFor(0)[0]).toContain( 'getInitialState was defined on ClassicProperties, ' + 'a plain JavaScript class.' ); - expect((console.error).argsForCall[1][0]).toContain( + expect((console.error).calls.argsFor(1)[0]).toContain( 'getDefaultProps was defined on ClassicProperties, ' + 'a plain JavaScript class.' ); - expect((console.error).argsForCall[2][0]).toContain( + expect((console.error).calls.argsFor(2)[0]).toContain( 'propTypes was defined as an instance property on ClassicProperties.' ); - expect((console.error).argsForCall[3][0]).toContain( + expect((console.error).calls.argsFor(3)[0]).toContain( 'contextTypes was defined as an instance property on ClassicProperties.' ); }); @@ -456,8 +456,8 @@ describe('ReactTypeScriptClass', function() { test(React.createElement(MisspelledComponent1), 'SPAN', 'foo'); - expect((console.error).argsForCall.length).toBe(1); - expect((console.error).argsForCall[0][0]).toBe( + expect((console.error).calls.count()).toBe(1); + expect((console.error).calls.argsFor(0)[0]).toBe( 'Warning: ' + 'MisspelledComponent1 has a method called componentShouldUpdate(). Did ' + 'you mean shouldComponentUpdate()? The name is phrased as a question ' + @@ -470,8 +470,8 @@ describe('ReactTypeScriptClass', function() { test(React.createElement(MisspelledComponent2), 'SPAN', 'foo'); - expect((console.error).argsForCall.length).toBe(1); - expect((console.error).argsForCall[0][0]).toBe( + expect((console.error).calls.count()).toBe(1); + expect((console.error).calls.argsFor(0)[0]).toBe( 'Warning: ' + 'MisspelledComponent2 has a method called componentWillRecieveProps(). ' + 'Did you mean componentWillReceiveProps()?' @@ -488,11 +488,11 @@ describe('ReactTypeScriptClass', function() { expect(() => instance.isMounted()).toThrow(); expect(() => instance.setProps({ name: 'bar' })).toThrow(); expect(() => instance.replaceProps({ name: 'bar' })).toThrow(); - expect((console.error).argsForCall.length).toBe(2); - expect((console.error).argsForCall[0][0]).toContain( + expect((console.error).calls.count()).toBe(2); + expect((console.error).calls.argsFor(0)[0]).toContain( 'replaceState(...) is deprecated in plain JavaScript React classes' ); - expect((console.error).argsForCall[1][0]).toContain( + expect((console.error).calls.argsFor(1)[0]).toContain( 'isMounted(...) is deprecated in plain JavaScript React classes' ); }); diff --git a/src/isomorphic/modern/element/__tests__/ReactJSXElement-test.js b/src/isomorphic/modern/element/__tests__/ReactJSXElement-test.js index 95126ca11191f..5bfbf4b96faab 100644 --- a/src/isomorphic/modern/element/__tests__/ReactJSXElement-test.js +++ b/src/isomorphic/modern/element/__tests__/ReactJSXElement-test.js @@ -100,21 +100,21 @@ describe('ReactJSXElement', function() { var a = 1; var element = {a}; expect(element.props.children).toBe(a); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('does not override children if no JSX children are provided', function() { spyOn(console, 'error'); var element = ; expect(element.props.children).toBe('text'); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('overrides children if null is provided as a JSX child', function() { spyOn(console, 'error'); var element = {null}; expect(element.props.children).toBe(null); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('merges JSX children onto the children prop in an array', function() { @@ -124,7 +124,7 @@ describe('ReactJSXElement', function() { var c = 3; var element = {a}{b}{c}; expect(element.props.children).toEqual([1, 2, 3]); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('allows static methods to be called using the type property', function() { @@ -141,7 +141,7 @@ describe('ReactJSXElement', function() { var element = ; expect(element.type.someStaticMethod()).toBe('someReturnValue'); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('identifies valid elements', function() { diff --git a/src/isomorphic/modern/element/__tests__/ReactJSXElementValidator-test.js b/src/isomorphic/modern/element/__tests__/ReactJSXElementValidator-test.js index 1e2890e9f0fd6..7c00f383311e2 100644 --- a/src/isomorphic/modern/element/__tests__/ReactJSXElementValidator-test.js +++ b/src/isomorphic/modern/element/__tests__/ReactJSXElementValidator-test.js @@ -47,8 +47,8 @@ describe('ReactJSXElementValidator', function() { void {[, ]}; - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'Each child in an array or iterator should have a unique "key" prop.' ); }); @@ -74,8 +74,8 @@ describe('ReactJSXElementValidator', function() { ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'Each child in an array or iterator should have a unique "key" prop. ' + 'Check the render method of `InnerComponent`. ' + 'It was passed a child from ComponentWrapper. ' @@ -99,8 +99,8 @@ describe('ReactJSXElementValidator', function() { void {iterable}; - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'Each child in an array or iterator should have a unique "key" prop.' ); }); @@ -110,7 +110,7 @@ describe('ReactJSXElementValidator', function() { void {[, ]}; - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('does not warns for iterable elements with keys', function() { @@ -133,7 +133,7 @@ describe('ReactJSXElementValidator', function() { void {iterable}; - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('does not warn for numeric keys in entry iterable as a child', function() { @@ -154,7 +154,7 @@ describe('ReactJSXElementValidator', function() { void {iterable}; - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('does not warn when the element is directly as children', function() { @@ -162,7 +162,7 @@ describe('ReactJSXElementValidator', function() { void ; - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('does not warn when the child array contains non-elements', function() { @@ -170,7 +170,7 @@ describe('ReactJSXElementValidator', function() { void {[{}, {}]}; - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); // TODO: These warnings currently come from the composite component, but @@ -195,7 +195,7 @@ describe('ReactJSXElementValidator', function() { } } ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Failed propType: ' + 'Invalid prop `color` of type `number` supplied to `MyComp`, ' + 'expected `string`. Check the render method of `ParentComp`.' @@ -213,25 +213,25 @@ describe('ReactJSXElementValidator', function() { void ; void ; void ; - expect(console.error.calls.length).toBe(4); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(4); + expect(console.error.calls.argsFor(0)[0]).toContain( 'type should not be null, undefined, boolean, or number. It should be ' + 'a string (for DOM elements) or a ReactClass (for composite components).' ); - expect(console.error.argsForCall[1][0]).toContain( + expect(console.error.calls.argsFor(1)[0]).toContain( 'type should not be null, undefined, boolean, or number. It should be ' + 'a string (for DOM elements) or a ReactClass (for composite components).' ); - expect(console.error.argsForCall[2][0]).toContain( + expect(console.error.calls.argsFor(2)[0]).toContain( 'type should not be null, undefined, boolean, or number. It should be ' + 'a string (for DOM elements) or a ReactClass (for composite components).' ); - expect(console.error.argsForCall[3][0]).toContain( + expect(console.error.calls.argsFor(3)[0]).toContain( 'type should not be null, undefined, boolean, or number. It should be ' + 'a string (for DOM elements) or a ReactClass (for composite components).' ); void
; - expect(console.error.calls.length).toBe(4); + expect(console.error.calls.count()).toBe(4); }); it('should check default prop values', function() { @@ -241,8 +241,8 @@ describe('ReactJSXElementValidator', function() { ReactTestUtils.renderIntoDocument(); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Failed propType: ' + 'Required prop `prop` was not specified in `RequiredPropComponent`.' ); @@ -253,8 +253,8 @@ describe('ReactJSXElementValidator', function() { ReactTestUtils.renderIntoDocument(); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Failed propType: ' + 'Required prop `prop` was not specified in `RequiredPropComponent`.' ); @@ -266,13 +266,13 @@ describe('ReactJSXElementValidator', function() { ReactTestUtils.renderIntoDocument(); ReactTestUtils.renderIntoDocument(); - expect(console.error.calls.length).toBe(2); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(2); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: Failed propType: ' + 'Required prop `prop` was not specified in `RequiredPropComponent`.' ); - expect(console.error.argsForCall[1][0]).toBe( + expect(console.error.calls.argsFor(1)[0]).toBe( 'Warning: Failed propType: ' + 'Invalid prop `prop` of type `number` supplied to ' + '`RequiredPropComponent`, expected `string`.' @@ -281,7 +281,7 @@ describe('ReactJSXElementValidator', function() { ReactTestUtils.renderIntoDocument(); // Should not error for strings - expect(console.error.calls.length).toBe(2); + expect(console.error.calls.count()).toBe(2); }); it('should warn on invalid prop types', function() { @@ -299,8 +299,8 @@ describe('ReactJSXElementValidator', function() { prop: null, }; ReactTestUtils.renderIntoDocument(); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'NullPropTypeComponent: prop type `prop` is invalid; it must be a ' + 'function, usually from React.PropTypes.' ); @@ -317,8 +317,8 @@ describe('ReactJSXElementValidator', function() { prop: null, }; ReactTestUtils.renderIntoDocument(); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'NullContextTypeComponent: context type `prop` is invalid; it must ' + 'be a function, usually from React.PropTypes.' ); @@ -335,8 +335,8 @@ describe('ReactJSXElementValidator', function() { prop: 'foo', }); ReactTestUtils.renderIntoDocument(); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'getDefaultProps is only used on classic React.createClass definitions.' + ' Use a static property named `defaultProps` instead.' ); diff --git a/src/renderers/dom/__tests__/ReactDOMProduction-test.js b/src/renderers/dom/__tests__/ReactDOMProduction-test.js index dd5a96a988596..718909ed86894 100644 --- a/src/renderers/dom/__tests__/ReactDOMProduction-test.js +++ b/src/renderers/dom/__tests__/ReactDOMProduction-test.js @@ -37,7 +37,7 @@ describe('ReactDOMProduction', function() { spyOn(console, 'error'); warning(false, 'Do cows go moo?'); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('should use prod React', function() { @@ -46,7 +46,7 @@ describe('ReactDOMProduction', function() { // no key warning void
{[]}
; - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('should handle a simple flow', function() { diff --git a/src/renderers/dom/client/__tests__/ReactBrowserEventEmitter-test.js b/src/renderers/dom/client/__tests__/ReactBrowserEventEmitter-test.js index 9de6b2e8e2862..009bc5d223608 100644 --- a/src/renderers/dom/client/__tests__/ReactBrowserEventEmitter-test.js +++ b/src/renderers/dom/client/__tests__/ReactBrowserEventEmitter-test.js @@ -271,7 +271,7 @@ describe('ReactBrowserEventEmitter', function() { expect(idCallOrder[0]).toBe(getInternal(CHILD)); expect(idCallOrder[1]).toBe(getInternal(PARENT)); expect(idCallOrder[2]).toBe(getInternal(GRANDPARENT)); - expect(console.error.calls.length).toEqual(0); + expect(console.error.calls.count()).toEqual(0); }); /** @@ -388,7 +388,7 @@ describe('ReactBrowserEventEmitter', function() { spyOn(EventListener, 'listen'); ReactBrowserEventEmitter.listenTo(ON_CLICK_KEY, document); ReactBrowserEventEmitter.listenTo(ON_CLICK_KEY, document); - expect(EventListener.listen.calls.length).toBe(1); + expect(EventListener.listen.calls.count()).toBe(1); }); it('should work with event plugins without dependencies', function() { @@ -396,7 +396,7 @@ describe('ReactBrowserEventEmitter', function() { ReactBrowserEventEmitter.listenTo(ON_CLICK_KEY, document); - expect(EventListener.listen.argsForCall[0][1]).toBe('click'); + expect(EventListener.listen.calls.argsFor(0)[1]).toBe('click'); }); it('should work with event plugins with dependencies', function() { @@ -406,8 +406,8 @@ describe('ReactBrowserEventEmitter', function() { ReactBrowserEventEmitter.listenTo(ON_CHANGE_KEY, document); var setEventListeners = []; - var listenCalls = EventListener.listen.argsForCall; - var captureCalls = EventListener.capture.argsForCall; + var listenCalls = EventListener.listen.calls.allArgs(); + var captureCalls = EventListener.capture.calls.allArgs(); for (var i = 0; i < listenCalls.length; i++) { setEventListeners.push(listenCalls[i][1]); } diff --git a/src/renderers/dom/client/__tests__/ReactDOM-test.js b/src/renderers/dom/client/__tests__/ReactDOM-test.js index 9c3cef57f90df..4576cf9c8a7f1 100644 --- a/src/renderers/dom/client/__tests__/ReactDOM-test.js +++ b/src/renderers/dom/client/__tests__/ReactDOM-test.js @@ -115,7 +115,7 @@ describe('ReactDOM', function() { spyOn(console, 'error'); var element = React.DOM.div(); expect(element.type).toBe('div'); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('throws in render() if the mount callback is not a function', function() { @@ -133,15 +133,15 @@ describe('ReactDOM', function() { }); var myDiv = document.createElement('div'); - expect(() => ReactDOM.render(, myDiv, 'no')).toThrow( + expect(() => ReactDOM.render(, myDiv, 'no')).toThrowError( 'ReactDOM.render(...): Expected the last optional `callback` argument ' + 'to be a function. Instead received: string.' ); - expect(() => ReactDOM.render(, myDiv, {})).toThrow( + expect(() => ReactDOM.render(, myDiv, {})).toThrowError( 'ReactDOM.render(...): Expected the last optional `callback` argument ' + 'to be a function. Instead received: Object.' ); - expect(() => ReactDOM.render(, myDiv, new Foo())).toThrow( + expect(() => ReactDOM.render(, myDiv, new Foo())).toThrowError( 'ReactDOM.render(...): Expected the last optional `callback` argument ' + 'to be a function. Instead received: Foo (keys: a, b).' ); @@ -164,15 +164,15 @@ describe('ReactDOM', function() { var myDiv = document.createElement('div'); ReactDOM.render(, myDiv); - expect(() => ReactDOM.render(, myDiv, 'no')).toThrow( + expect(() => ReactDOM.render(, myDiv, 'no')).toThrowError( 'ReactDOM.render(...): Expected the last optional `callback` argument ' + 'to be a function. Instead received: string.' ); - expect(() => ReactDOM.render(, myDiv, {})).toThrow( + expect(() => ReactDOM.render(, myDiv, {})).toThrowError( 'ReactDOM.render(...): Expected the last optional `callback` argument ' + 'to be a function. Instead received: Object.' ); - expect(() => ReactDOM.render(, myDiv, new Foo())).toThrow( + expect(() => ReactDOM.render(, myDiv, new Foo())).toThrowError( 'ReactDOM.render(...): Expected the last optional `callback` argument ' + 'to be a function. Instead received: Foo (keys: a, b).' ); diff --git a/src/renderers/dom/client/__tests__/ReactMount-test.js b/src/renderers/dom/client/__tests__/ReactMount-test.js index 96ca4aef3336b..b72a26dec551f 100644 --- a/src/renderers/dom/client/__tests__/ReactMount-test.js +++ b/src/renderers/dom/client/__tests__/ReactMount-test.js @@ -44,7 +44,7 @@ describe('ReactMount', function() { var nodeArray = document.getElementsByTagName('div'); expect(function() { ReactDOM.unmountComponentAtNode(nodeArray); - }).toThrow( + }).toThrowError( 'unmountComponentAtNode(...): Target container is not a DOM element.' ); }); @@ -53,7 +53,7 @@ describe('ReactMount', function() { it('throws when given a string', function() { expect(function() { ReactTestUtils.renderIntoDocument('div'); - }).toThrow( + }).toThrowError( 'ReactDOM.render(): Invalid component element. Instead of passing a ' + 'string like \'div\', pass React.createElement(\'div\') or
.' ); @@ -67,7 +67,7 @@ describe('ReactMount', function() { }); expect(function() { ReactTestUtils.renderIntoDocument(Component); - }).toThrow( + }).toThrowError( 'ReactDOM.render(): Invalid component element. Instead of passing a ' + 'class like Foo, pass React.createElement(Foo) or .' ); @@ -133,12 +133,12 @@ describe('ReactMount', function() { spyOn(console, 'error'); ReactMount.render(
, container); - expect(console.error.calls.length).toBe(1); + expect(console.error.calls.count()).toBe(1); container.innerHTML = ' ' + ReactDOMServer.renderToString(
); ReactMount.render(
, container); - expect(console.error.calls.length).toBe(2); + expect(console.error.calls.count()).toBe(2); }); it('should not warn if mounting into non-empty node', function() { @@ -147,7 +147,7 @@ describe('ReactMount', function() { spyOn(console, 'error'); ReactMount.render(
, container); - expect(console.error.calls.length).toBe(0); + expect(console.error.calls.count()).toBe(0); }); it('should warn when mounting into document.body', function() { @@ -157,8 +157,8 @@ describe('ReactMount', function() { ReactMount.render(
, iFrame.contentDocument.body); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'Rendering components directly into document.body is discouraged' ); }); @@ -174,8 +174,8 @@ describe('ReactMount', function() {
This markup contains an nbsp entity:   client text
, div ); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( ' (client) nbsp entity:   client text
\n' + ' (server) nbsp entity:   server text
' ); @@ -217,8 +217,8 @@ describe('ReactMount', function() { spyOn(console, 'error'); var rootNode = container.firstChild; ReactDOM.render(, rootNode); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: render(...): Replacing React-rendered children with a new ' + 'root component. If you intended to update the children of this node, ' + 'you should instead have the existing children update their state and ' + @@ -300,10 +300,10 @@ describe('ReactMount', function() { ReactTestUtils.renderIntoDocument(); - expect(console.time.argsForCall.length).toBe(1); - expect(console.time.argsForCall[0][0]).toBe('React mount: Foo'); - expect(console.timeEnd.argsForCall.length).toBe(1); - expect(console.timeEnd.argsForCall[0][0]).toBe('React mount: Foo'); + expect(console.time.calls.count()).toBe(1); + expect(console.time.calls.argsFor(0)[0]).toBe('React mount: Foo'); + expect(console.timeEnd.calls.count()).toBe(1); + expect(console.timeEnd.calls.argsFor(0)[0]).toBe('React mount: Foo'); } finally { ReactFeatureFlags.logTopLevelRenders = false; } diff --git a/src/renderers/dom/client/__tests__/ReactMountDestruction-test.js b/src/renderers/dom/client/__tests__/ReactMountDestruction-test.js index a4d8e39973101..c86d79bd44c48 100644 --- a/src/renderers/dom/client/__tests__/ReactMountDestruction-test.js +++ b/src/renderers/dom/client/__tests__/ReactMountDestruction-test.js @@ -53,8 +53,8 @@ describe('ReactMount', function() { var rootDiv = mainContainerDiv.firstChild; spyOn(console, 'error'); ReactDOM.unmountComponentAtNode(rootDiv); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: unmountComponentAtNode(): The node you\'re attempting to ' + 'unmount was rendered by React and is not a top-level container. You ' + 'may have accidentally passed in a React root node instead of its ' + @@ -77,8 +77,8 @@ describe('ReactMount', function() { var nonRootDiv = mainContainerDiv.firstChild.firstChild; spyOn(console, 'error'); ReactDOM.unmountComponentAtNode(nonRootDiv); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: unmountComponentAtNode(): The node you\'re attempting to ' + 'unmount was rendered by React and is not a top-level container. ' + 'Instead, have the parent component update its state and rerender in ' + diff --git a/src/renderers/dom/client/__tests__/ReactRenderDocument-test.js b/src/renderers/dom/client/__tests__/ReactRenderDocument-test.js index 1d96826626c4c..6f2b5d3c2d763 100644 --- a/src/renderers/dom/client/__tests__/ReactRenderDocument-test.js +++ b/src/renderers/dom/client/__tests__/ReactRenderDocument-test.js @@ -94,7 +94,7 @@ describe('rendering React components at document', function() { expect(function() { ReactDOM.unmountComponentAtNode(testDocument); - }).toThrow(UNMOUNT_INVARIANT_MESSAGE); + }).toThrowError(UNMOUNT_INVARIANT_MESSAGE); expect(testDocument.body.innerHTML).toBe('Hello world'); }); @@ -142,7 +142,7 @@ describe('rendering React components at document', function() { // Reactive update expect(function() { ReactDOM.render(, testDocument); - }).toThrow(UNMOUNT_INVARIANT_MESSAGE); + }).toThrowError(UNMOUNT_INVARIANT_MESSAGE); expect(testDocument.body.innerHTML).toBe('Hello world'); }); @@ -201,7 +201,7 @@ describe('rendering React components at document', function() { expect(function() { // Notice the text is different! ReactDOM.render(, testDocument); - }).toThrow( + }).toThrowError( 'You\'re trying to render a component to the document using ' + 'server rendering but the checksum was invalid. This usually ' + 'means you rendered a different component type or props on ' + @@ -237,7 +237,7 @@ describe('rendering React components at document', function() { expect(function() { ReactDOM.render(, container); - }).toThrow( + }).toThrowError( 'You\'re trying to render a component to the document but you didn\'t ' + 'use server rendering. We can\'t do this without using server ' + 'rendering due to cross-browser quirks. See ' + diff --git a/src/renderers/dom/client/__tests__/findDOMNode-test.js b/src/renderers/dom/client/__tests__/findDOMNode-test.js index 1f861dd3454c5..185e67c516fd7 100644 --- a/src/renderers/dom/client/__tests__/findDOMNode-test.js +++ b/src/renderers/dom/client/__tests__/findDOMNode-test.js @@ -37,7 +37,7 @@ describe('findDOMNode', function() { it('findDOMNode should reject random objects', function() { expect(function() { ReactDOM.findDOMNode({foo: 'bar'}); - }).toThrow( + }).toThrowError( 'Element appears to be neither ReactComponent nor DOMNode (keys: foo)' ); }); @@ -53,7 +53,7 @@ describe('findDOMNode', function() { var inst = ReactDOM.render(, container); ReactDOM.unmountComponentAtNode(container); - expect(() => ReactDOM.findDOMNode(inst)).toThrow( + expect(() => ReactDOM.findDOMNode(inst)).toThrowError( 'findDOMNode was called on an unmounted component.' ); }); diff --git a/src/renderers/dom/client/syntheticEvents/__tests__/SyntheticEvent-test.js b/src/renderers/dom/client/syntheticEvents/__tests__/SyntheticEvent-test.js index a8799c8f87ad8..98f1690efda2b 100644 --- a/src/renderers/dom/client/syntheticEvents/__tests__/SyntheticEvent-test.js +++ b/src/renderers/dom/client/syntheticEvents/__tests__/SyntheticEvent-test.js @@ -87,9 +87,9 @@ describe('SyntheticEvent', function() { expect(syntheticEvent.nativeEvent).toBe(null); expect(syntheticEvent.target).toBe(null); // once for each property accessed - expect(console.error.calls.length).toBe(3); + expect(console.error.calls.count()).toBe(3); // assert the first warning for accessing `type` - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: This synthetic event is reused for performance reasons. If ' + 'you\'re seeing this, you\'re accessing the property `type` on a ' + 'released/nullified synthetic event. This is set to null. If you must ' + @@ -104,8 +104,8 @@ describe('SyntheticEvent', function() { var syntheticEvent = createEvent({srcElement: target}); syntheticEvent.destructor(); expect(syntheticEvent.type = 'MouseEvent').toBe('MouseEvent'); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: This synthetic event is reused for performance reasons. If ' + 'you\'re seeing this, you\'re setting the property `type` on a ' + 'released/nullified synthetic event. This is effectively a no-op. If you must ' + @@ -119,8 +119,8 @@ describe('SyntheticEvent', function() { var syntheticEvent = createEvent({}); SyntheticEvent.release(syntheticEvent); syntheticEvent.preventDefault(); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: This synthetic event is reused for performance reasons. If ' + 'you\'re seeing this, you\'re accessing the method `preventDefault` on a ' + 'released/nullified synthetic event. This is a no-op function. If you must ' + @@ -134,8 +134,8 @@ describe('SyntheticEvent', function() { var syntheticEvent = createEvent({}); SyntheticEvent.release(syntheticEvent); syntheticEvent.stopPropagation(); - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: This synthetic event is reused for performance reasons. If ' + 'you\'re seeing this, you\'re accessing the method `stopPropagation` on a ' + 'released/nullified synthetic event. This is a no-op function. If you must ' + @@ -156,13 +156,13 @@ describe('SyntheticEvent', function() { } var instance = ReactDOM.render(
, element); ReactTestUtils.Simulate.click(ReactDOM.findDOMNode(instance)); - expect(console.error.calls.length).toBe(0); + expect(console.error.calls.count()).toBe(0); // access a property to cause the warning event.nativeEvent; // eslint-disable-line no-unused-expressions - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: This synthetic event is reused for performance reasons. If ' + 'you\'re seeing this, you\'re accessing the property `nativeEvent` on a ' + 'released/nullified synthetic event. This is set to null. If you must ' + @@ -178,15 +178,15 @@ describe('SyntheticEvent', function() { SyntheticEvent.release(syntheticEvent); expect(syntheticEvent.foo).toBe('bar'); if (typeof Proxy === 'function') { - expect(console.error.calls.length).toBe(1); - expect(console.error.argsForCall[0][0]).toBe( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( 'Warning: This synthetic event is reused for performance reasons. If ' + 'you\'re seeing this, you\'re adding a new property in the synthetic ' + 'event object. The property is never released. ' + 'See https://fb.me/react-event-pooling for more information.' ); } else { - expect(console.error.calls.length).toBe(0); + expect(console.error.calls.count()).toBe(0); } }); }); diff --git a/src/renderers/dom/client/wrappers/__tests__/ReactDOMInput-test.js b/src/renderers/dom/client/wrappers/__tests__/ReactDOMInput-test.js index 5f0da993e4a95..1e1513c307849 100644 --- a/src/renderers/dom/client/wrappers/__tests__/ReactDOMInput-test.js +++ b/src/renderers/dom/client/wrappers/__tests__/ReactDOMInput-test.js @@ -264,29 +264,29 @@ describe('ReactDOMInput', function() { it('should warn with value and no onChange handler', function() { var link = new ReactLink('yolo', jest.fn()); ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( '`valueLink` prop on `input` is deprecated; set `value` and `onChange` instead.' ); ReactTestUtils.renderIntoDocument( ); - expect(console.error.argsForCall.length).toBe(1); + expect(console.error.calls.count()).toBe(1); ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall.length).toBe(2); + expect(console.error.calls.count()).toBe(2); }); it('should warn with value and no onChange handler and readOnly specified', function() { ReactTestUtils.renderIntoDocument( ); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); ReactTestUtils.renderIntoDocument( ); - expect(console.error.argsForCall.length).toBe(1); + expect(console.error.calls.count()).toBe(1); }); it('should have a this value of undefined if bind is not used', function() { @@ -342,8 +342,8 @@ describe('ReactDOMInput', function() { var node = document.createElement('div'); var link = new ReactLink(true, jest.fn()); ReactDOM.render(, node); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( '`checkedLink` prop on `input` is deprecated; set `value` and `onChange` instead.' ); @@ -354,27 +354,27 @@ describe('ReactDOMInput', function() { onChange={jest.fn()} /> ); - expect(console.error.argsForCall.length).toBe(1); + expect(console.error.calls.count()).toBe(1); ReactTestUtils.renderIntoDocument( ); - expect(console.error.argsForCall.length).toBe(1); + expect(console.error.calls.count()).toBe(1); ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall.length).toBe(2); + expect(console.error.calls.count()).toBe(2); }); it('should warn with checked and no onChange handler with readOnly specified', function() { ReactTestUtils.renderIntoDocument( ); - expect(console.error.argsForCall.length).toBe(0); + expect(console.error.calls.count()).toBe(0); ReactTestUtils.renderIntoDocument( ); - expect(console.error.argsForCall.length).toBe(1); + expect(console.error.calls.count()).toBe(1); }); it('should throw if both checked and checkedLink are provided', function() { @@ -416,21 +416,21 @@ describe('ReactDOMInput', function() { it('should warn if value is null', function() { ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.argsFor(0)[0]).toContain( '`value` prop on `input` should not be null. ' + 'Consider using the empty string to clear the component or `undefined` ' + 'for uncontrolled components.' ); ReactTestUtils.renderIntoDocument(); - expect(console.error.argsForCall.length).toBe(1); + expect(console.error.calls.count()).toBe(1); }); it('should warn if checked and defaultChecked props are specified', function() { ReactTestUtils.renderIntoDocument( ); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.argsFor(0)[0]).toContain( 'A component contains an input of type radio with both checked and defaultChecked props. ' + 'Input elements must be either controlled or uncontrolled ' + '(specify either the checked prop, or the defaultChecked prop, but not ' + @@ -442,14 +442,14 @@ describe('ReactDOMInput', function() { ReactTestUtils.renderIntoDocument( ); - expect(console.error.argsForCall.length).toBe(1); + expect(console.error.calls.count()).toBe(1); }); it('should warn if value and defaultValue props are specified', function() { ReactTestUtils.renderIntoDocument( ); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.argsFor(0)[0]).toContain( 'A component contains an input of type text with both value and defaultValue props. ' + 'Input elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + @@ -461,7 +461,7 @@ describe('ReactDOMInput', function() { ReactTestUtils.renderIntoDocument( ); - expect(console.error.argsForCall.length).toBe(1); + expect(console.error.calls.count()).toBe(1); }); it('should warn if controlled input switches to uncontrolled', function() { @@ -469,8 +469,8 @@ describe('ReactDOMInput', function() { var container = document.createElement('div'); ReactDOM.render(stub, container); ReactDOM.render(, container); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'A component is changing a controlled input of type text to be uncontrolled. ' + 'Input elements should not switch from controlled to uncontrolled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + @@ -483,8 +483,8 @@ describe('ReactDOMInput', function() { var container = document.createElement('div'); ReactDOM.render(stub, container); ReactDOM.render(, container); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'A component is changing a controlled input of type text to be uncontrolled. ' + 'Input elements should not switch from controlled to uncontrolled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + @@ -497,8 +497,8 @@ describe('ReactDOMInput', function() { var container = document.createElement('div'); ReactDOM.render(stub, container); ReactDOM.render(, container); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'A component is changing an uncontrolled input of type text to be controlled. ' + 'Input elements should not switch from uncontrolled to controlled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + @@ -511,8 +511,8 @@ describe('ReactDOMInput', function() { var container = document.createElement('div'); ReactDOM.render(stub, container); ReactDOM.render(, container); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'A component is changing a controlled input of type checkbox to be uncontrolled. ' + 'Input elements should not switch from controlled to uncontrolled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + @@ -525,8 +525,8 @@ describe('ReactDOMInput', function() { var container = document.createElement('div'); ReactDOM.render(stub, container); ReactDOM.render(, container); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'A component is changing a controlled input of type checkbox to be uncontrolled. ' + 'Input elements should not switch from controlled to uncontrolled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + @@ -539,8 +539,8 @@ describe('ReactDOMInput', function() { var container = document.createElement('div'); ReactDOM.render(stub, container); ReactDOM.render(, container); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'A component is changing an uncontrolled input of type checkbox to be controlled. ' + 'Input elements should not switch from uncontrolled to controlled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + @@ -553,8 +553,8 @@ describe('ReactDOMInput', function() { var container = document.createElement('div'); ReactDOM.render(stub, container); ReactDOM.render(, container); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'A component is changing a controlled input of type radio to be uncontrolled. ' + 'Input elements should not switch from controlled to uncontrolled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + @@ -567,8 +567,8 @@ describe('ReactDOMInput', function() { var container = document.createElement('div'); ReactDOM.render(stub, container); ReactDOM.render(, container); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'A component is changing a controlled input of type radio to be uncontrolled. ' + 'Input elements should not switch from controlled to uncontrolled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + @@ -581,8 +581,8 @@ describe('ReactDOMInput', function() { var container = document.createElement('div'); ReactDOM.render(stub, container); ReactDOM.render(, container); - expect(console.error.argsForCall.length).toBe(1); - expect(console.error.argsForCall[0][0]).toContain( + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toContain( 'A component is changing an uncontrolled input of type radio to be controlled. ' + 'Input elements should not switch from uncontrolled to controlled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + @@ -596,7 +596,7 @@ describe('ReactDOMInput', function() { } var log = []; var originalCreateElement = document.createElement; - spyOn(document, 'createElement').andCallFake(function(type) { + spyOn(document, 'createElement').and.callFake(function(type) { var el = originalCreateElement.apply(this, arguments); if (type === 'input') { Object.defineProperty(el, 'value', { @@ -605,7 +605,7 @@ describe('ReactDOMInput', function() { log.push('set value'); }, }); - spyOn(el, 'setAttribute').andCallFake(function(name, value) { + spyOn(el, 'setAttribute').and.callFake(function(name, value) { log.push('set ' + name); }); } diff --git a/src/renderers/dom/client/wrappers/__tests__/ReactDOMOption-test.js b/src/renderers/dom/client/wrappers/__tests__/ReactDOMOption-test.js index 3f9bf1fbaac11..d82219a9c5a93 100644 --- a/src/renderers/dom/client/wrappers/__tests__/ReactDOMOption-test.js +++ b/src/renderers/dom/client/wrappers/__tests__/ReactDOMOption-test.js @@ -39,8 +39,8 @@ describe('ReactDOMOption', function() { expect(node.innerHTML).toBe('1 2'); ReactTestUtils.renderIntoDocument(