diff --git a/grunt/tasks/jest.js b/grunt/tasks/jest.js
index 679e26c3d0493..94d8f2022c926 100644
--- a/grunt/tasks/jest.js
+++ b/grunt/tasks/jest.js
@@ -73,7 +73,7 @@ function run(done, configPath) {
grunt.log.writeln('running jest');
var args = [
- path.join('node_modules', 'jest-cli', 'bin', 'jest'),
+ path.join('node_modules', 'jest', 'bin', 'jest'),
'--runInBand',
'--no-watchman',
];
@@ -83,7 +83,12 @@ function run(done, configPath) {
grunt.util.spawn({
cmd: 'node',
args: args,
- opts: { stdio: 'inherit', env: { NODE_ENV: 'test' } },
+ opts: {
+ stdio: 'inherit',
+ env: Object.assign({}, process.env, {
+ NODE_ENV: 'test',
+ }),
+ },
}, function(spawnErr, result, code) {
if (spawnErr) {
onError(spawnErr);
diff --git a/package.json b/package.json
index 1b20001d2e6ff..82561f1482727 100644
--- a/package.json
+++ b/package.json
@@ -52,7 +52,7 @@
"gulp-babel": "^6.0.0",
"gulp-flatten": "^0.2.0",
"gzip-js": "~0.3.2",
- "jest-cli": "^12.0.2",
+ "jest": "^12.1.1",
"loose-envify": "^1.1.0",
"object-assign": "^4.1.0",
"platform": "^1.1.0",
@@ -87,7 +87,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..141b0fa8366f8 100644
--- a/scripts/jest/test-framework-setup.js
+++ b/scripts/jest/test-framework-setup.js
@@ -2,34 +2,49 @@
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.
+console.error = newError;
- if (console.error !== newError && !console.error.isSpy) {
- var expectationResult = new jasmine.ExpectationResult({
- passed: false,
- message: 'Test did not tear down console.error mock properly.',
- });
- env.currentSpec.addMatcherResult(expectationResult);
- }
+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();
});
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(
, 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/addons/transitions/__tests__/ReactTransitionGroup-test.js b/src/addons/transitions/__tests__/ReactTransitionGroup-test.js
index 9617c57f4bbca..d19d4bb91dd98 100644
--- a/src/addons/transitions/__tests__/ReactTransitionGroup-test.js
+++ b/src/addons/transitions/__tests__/ReactTransitionGroup-test.js
@@ -286,14 +286,14 @@ describe('ReactTransitionGroup', function() {
ReactDOM.render(, container);
- expect(console.error.argsForCall.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: flattenChildren(...): ' +
'Encountered two children with the same key, `1`. ' +
'Child keys must be unique; when two children share a key, ' +
'only the first child will be used.'
);
- expect(normalizeCodeLocInfo(console.error.argsForCall[1][0])).toBe(
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
'Warning: flattenChildren(...): ' +
'Encountered two children with the same key, `1`. ' +
'Child keys must be unique; when two children share a key, ' +
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 972093d8f54ad..37e77d7de8f11 100644
--- a/src/isomorphic/classic/__tests__/ReactContextValidator-test.js
+++ b/src/isomorphic/classic/__tests__/ReactContextValidator-test.js
@@ -149,8 +149,8 @@ describe('ReactContextValidator', function() {
ReactTestUtils.renderIntoDocument();
- expect(console.error.argsForCall.length).toBe(1);
- expect(normalizeCodeLocInfo(console.error.argsForCall[0][0])).toBe(
+ expect(console.error.calls.count()).toBe(1);
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Failed context type: ' +
'Required context `foo` was not specified in `Component`.\n' +
' in Component (at **)'
@@ -177,7 +177,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: {
@@ -197,8 +197,8 @@ describe('ReactContextValidator', function() {
ReactTestUtils.renderIntoDocument();
- expect(console.error.argsForCall.length).toBe(2);
- expect(normalizeCodeLocInfo(console.error.argsForCall[1][0])).toBe(
+ expect(console.error.calls.count()).toBe(2);
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
'Warning: Failed context type: ' +
'Invalid context `foo` of type `number` supplied ' +
'to `Component`, expected `string`.\n' +
@@ -226,8 +226,8 @@ describe('ReactContextValidator', function() {
});
ReactTestUtils.renderIntoDocument();
- expect(console.error.argsForCall.length).toBe(1);
- expect(normalizeCodeLocInfo(console.error.argsForCall[0][0])).toBe(
+ expect(console.error.calls.count()).toBe(1);
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Failed childContext type: ' +
'Required child context `foo` was not specified in `Component`.\n' +
' in Component (at **)'
@@ -235,8 +235,8 @@ describe('ReactContextValidator', function() {
ReactTestUtils.renderIntoDocument();
- expect(console.error.argsForCall.length).toBe(2);
- expect(normalizeCodeLocInfo(console.error.argsForCall[1][0])).toBe(
+ expect(console.error.calls.count()).toBe(2);
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
'Warning: Failed childContext type: ' +
'Invalid child context `foo` of type `number` ' +
'supplied to `Component`, expected `string`.\n' +
@@ -252,7 +252,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 011dbf9aa8b68..67bad42f3e31f 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 ' +
@@ -149,8 +149,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.'
);
@@ -208,7 +208,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() {
@@ -217,7 +217,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() {
@@ -226,7 +226,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('overrides children if undefined is provided as an argument', function() {
@@ -248,7 +248,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
@@ -272,7 +272,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
@@ -440,7 +440,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 322bcfb174e9f..ab57c8cae2fe4 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 prop type: ' +
'Invalid prop `color` of type `number` supplied to `Component`, ' +
'expected `string`.\n' +
diff --git a/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js b/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js
index 69872e3dd30d2..fe7acf3e60930 100644
--- a/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js
+++ b/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js
@@ -44,8 +44,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.'
);
});
@@ -74,8 +74,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. '
@@ -98,8 +98,8 @@ describe('ReactElementValidator', function() {
];
ReactTestUtils.renderIntoDocument({divs});
- expect(console.error.argsForCall.length).toBe(1);
- expect(normalizeCodeLocInfo(console.error.argsForCall[0][0])).toBe(
+ expect(console.error.calls.count()).toBe(1);
+ expect(normalizeCodeLocInfo(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.\n' +
' in div (at **)'
@@ -115,8 +115,8 @@ describe('ReactElementValidator', function() {
];
ReactTestUtils.renderIntoDocument(
{divs}
);
- expect(console.error.argsForCall.length).toBe(1);
- expect(normalizeCodeLocInfo(console.error.argsForCall[0][0])).toBe(
+ expect(console.error.calls.count()).toBe(1);
+ expect(normalizeCodeLocInfo(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.\n' +
@@ -147,8 +147,8 @@ describe('ReactElementValidator', function() {
ReactTestUtils.renderIntoDocument();
- expect(console.error.argsForCall.length).toBe(1);
- expect(normalizeCodeLocInfo(console.error.argsForCall[0][0])).toBe(
+ expect(console.error.calls.count()).toBe(1);
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Each child in an array or iterator should have a unique ' +
'"key" prop. Check the render method of `Component`. See ' +
'https://fb.me/react-warning-keys for more information.\n' +
@@ -180,7 +180,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() {
@@ -201,8 +201,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.'
);
});
@@ -213,7 +213,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() {
@@ -237,7 +237,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() {
@@ -246,7 +246,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() {
@@ -255,7 +255,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
@@ -280,7 +280,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 prop type: ' +
'Invalid prop `color` of type `number` supplied to `MyComp`, ' +
'expected `string`.\n' +
@@ -295,29 +295,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() {
@@ -329,13 +329,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 ' +
@@ -358,8 +358,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 prop type: ' +
'Required prop `prop` was not specified in `Component`.\n' +
' in Component'
@@ -383,8 +383,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 prop type: ' +
'Required prop `prop` was not specified in `Component`.\n' +
' in Component'
@@ -410,14 +410,14 @@ 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 prop type: ' +
'Required prop `prop` was not specified in `Component`.\n' +
' in Component'
);
- expect(console.error.argsForCall[1][0]).toBe(
+ expect(console.error.calls.argsFor(1)[0]).toBe(
'Warning: Failed prop type: ' +
'Invalid prop `prop` of type `number` supplied to ' +
'`Component`, expected `string`.\n' +
@@ -429,7 +429,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() {
@@ -448,8 +448,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 ' +
@@ -467,14 +467,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() {
@@ -491,7 +491,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() {
@@ -534,8 +534,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 b217438abe5c4..14559720aeb0d 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,8 +849,8 @@ describe('ReactPropTypes', function() {
var instance = ;
instance = ReactTestUtils.renderIntoDocument(instance);
- expect(spy.argsForCall.length).toBe(1);
- expect(spy.argsForCall[0][1]).toBe('num');
+ expect(spy.calls.count()).toBe(1);
+ expect(spy.calls.argsFor(0)[1]).toBe('num');
});
it('should have been called even if the prop is not present', function() {
@@ -866,14 +866,13 @@ describe('ReactPropTypes', function() {
var instance = ;
instance = ReactTestUtils.renderIntoDocument(instance);
- expect(spy.argsForCall.length).toBe(1);
- expect(spy.argsForCall[0][1]).toBe('num');
+ expect(spy.calls.count()).toBe(1);
+ expect(spy.calls.argsFor(0)[1]).toBe('num');
});
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,9 +889,9 @@ describe('ReactPropTypes', function() {
var instance = ;
instance = ReactTestUtils.renderIntoDocument(instance);
- expect(console.error.argsForCall.length).toBe(1);
+ expect(console.error.calls.count()).toBe(1);
expect(
- console.error.argsForCall[0][0].replace(/\(at .+?:\d+\)/g, '(at **)')
+ console.error.calls.argsFor(0)[0].replace(/\(at .+?:\d+\)/g, '(at **)')
).toBe(
'Warning: Failed prop type: num must be 5!\n' +
' in Component (at **)'
@@ -902,8 +901,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;
}
@@ -918,7 +916,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..0d91c3a144f7d 100644
--- a/src/isomorphic/modern/class/__tests__/ReactClassEquivalence-test.js
+++ b/src/isomorphic/modern/class/__tests__/ReactClassEquivalence-test.js
@@ -11,24 +11,62 @@
'use strict';
-var MetaMatchers = require('MetaMatchers');
+var spawnSync = require('child_process').spawnSync;
+var path = require('path');
describe('ReactClassEquivalence', function() {
-
- beforeEach(function() {
- this.addMatchers(MetaMatchers);
- });
-
- var es6 = () => require('./ReactES6Class-test.js');
- var coffee = () => require('./ReactCoffeeScriptClass-test.coffee');
- var ts = () => require('./ReactTypeScriptClass-test.ts');
-
it('tests the same thing for es6 classes and CoffeeScript', function() {
- expect(coffee).toEqualSpecsIn(es6);
+ var result1 = runJest('ReactCoffeeScriptClass-test.coffee');
+ var result2 = runJest('ReactES6Class-test.js');
+ compareResults(result1, result2);
});
it('tests the same thing for es6 classes and TypeScript', function() {
- expect(ts).toEqualSpecsIn(es6);
+ var result1 = runJest('ReactTypeScriptClass-test.ts');
+ var result2 = runJest('ReactES6Class-test.js');
+ compareResults(result1, result2);
});
});
+
+function runJest(testFile) {
+ var cwd = process.cwd();
+ var jestBin = path.resolve('node_modules', '.bin', 'jest');
+ var setupFile = path.resolve(__dirname, 'setupSpecEquivalenceReporter.js');
+ var result = spawnSync('node', [
+ jestBin,
+ testFile,
+ '--setupTestFrameworkScriptFile',
+ setupFile,
+ ], {cwd});
+
+ if (result.error) {
+ throw result.error;
+ }
+
+ if (result.status !== 0) {
+ throw new Error(
+ 'jest process exited with: ' +
+ result.status +
+ '\n' +
+ 'stdout: ' +
+ result.stdout.toString() +
+ 'stderr: ' +
+ result.stderr.toString()
+ );
+ }
+
+ return result.stdout.toString();
+}
+
+function compareResults(a, b) {
+ var regexp = /^EQUIVALENCE.*$/gm;
+ var aSpecs = (a.match(regexp) || []).sort().join('\n');
+ var bSpecs = (b.match(regexp) || []).sort().join('\n');
+
+ if (aSpecs.length === 0 && bSpecs.length === 0) {
+ throw new Error('No spec results found in the output');
+ }
+
+ expect(aSpecs).toEqual(bSpecs);
+}
diff --git a/src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee b/src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee
index e7b1f574c579a..a9871ea6baa4d 100644
--- a/src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee
+++ b/src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee
@@ -51,8 +51,9 @@ 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')
+ undefined
it 'renders a simple stateless component with prop', ->
class Foo extends React.Component
@@ -62,6 +63,7 @@ describe 'ReactCoffeeScriptClass', ->
test React.createElement(Foo, bar: 'foo'), 'DIV', 'foo'
test React.createElement(Foo, bar: 'bar'), 'DIV', 'bar'
+ undefined
it 'renders based on state using initial values in this.props', ->
class Foo extends React.Component
@@ -74,6 +76,7 @@ describe 'ReactCoffeeScriptClass', ->
className: @state.bar
test React.createElement(Foo, initialValue: 'foo'), 'SPAN', 'foo'
+ undefined
it 'renders based on state using props in the constructor', ->
class Foo extends React.Component
@@ -94,6 +97,7 @@ describe 'ReactCoffeeScriptClass', ->
instance = test React.createElement(Foo, initialValue: 'foo'), 'DIV', 'foo'
instance.changeState()
test React.createElement(Foo), 'SPAN', 'bar'
+ undefined
it 'renders based on context in the constructor', ->
class Foo extends React.Component
@@ -125,6 +129,7 @@ describe 'ReactCoffeeScriptClass', ->
React.createElement Foo
test React.createElement(Outer), 'SPAN', 'foo'
+ undefined
it 'renders only once when setting state in componentWillMount', ->
renderCount = 0
@@ -141,6 +146,7 @@ describe 'ReactCoffeeScriptClass', ->
test React.createElement(Foo, initialValue: 'foo'), 'SPAN', 'bar'
expect(renderCount).toBe 1
+ undefined
it 'should throw with non-object in the initial state property', ->
[['an array'], 'a string', 1234].forEach (state) ->
@@ -153,9 +159,10 @@ describe 'ReactCoffeeScriptClass', ->
expect(->
test React.createElement(Foo), 'span', ''
- ).toThrow(
+ ).toThrowError(
'Foo.state: must be set to an object or null'
)
+ undefined
it 'should render with null in the initial state property', ->
class Foo extends React.Component
@@ -166,6 +173,7 @@ describe 'ReactCoffeeScriptClass', ->
span()
test React.createElement(Foo), 'SPAN', ''
+ undefined
it 'setState through an event handler', ->
class Foo extends React.Component
@@ -183,6 +191,7 @@ describe 'ReactCoffeeScriptClass', ->
test React.createElement(Foo, initialValue: 'foo'), 'DIV', 'foo'
attachedListener()
expect(renderedName).toBe 'bar'
+ undefined
it 'should not implicitly bind event handlers', ->
class Foo extends React.Component
@@ -199,6 +208,7 @@ describe 'ReactCoffeeScriptClass', ->
test React.createElement(Foo, initialValue: 'foo'), 'DIV', 'foo'
expect(attachedListener).toThrow()
+ undefined
it 'renders using forceUpdate even when there is no state', ->
class Foo extends React.Component
@@ -217,6 +227,7 @@ describe 'ReactCoffeeScriptClass', ->
test React.createElement(Foo, initialValue: 'foo'), 'DIV', 'foo'
attachedListener()
expect(renderedName).toBe 'bar'
+ undefined
it 'will call all the normal life cycle methods', ->
lifeCycles = []
@@ -266,6 +277,7 @@ describe 'ReactCoffeeScriptClass', ->
lifeCycles = [] # reset
ReactDOM.unmountComponentAtNode container
expect(lifeCycles).toEqual ['will-unmount']
+ undefined
it 'warns when classic properties are defined on the instance,
but does not invoke them.', ->
@@ -292,19 +304,20 @@ 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.'
)
+ undefined
it 'should warn when misspelling shouldComponentUpdate', ->
spyOn console, 'error'
@@ -317,12 +330,13 @@ 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.'
)
+ undefined
it 'should warn when misspelling componentWillReceiveProps', ->
spyOn console, 'error'
@@ -335,11 +349,12 @@ 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()?'
)
+ undefined
it 'should throw AND warn when trying to access classic APIs', ->
spyOn console, 'error'
@@ -349,13 +364,14 @@ 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'
)
+ undefined
it 'supports this.context passed via getChildContext', ->
class Bar extends React.Component
@@ -373,6 +389,7 @@ describe 'ReactCoffeeScriptClass', ->
React.createElement Bar
test React.createElement(Foo), 'DIV', 'bar-through-context'
+ undefined
it 'supports classic refs', ->
class Foo extends React.Component
@@ -383,8 +400,10 @@ describe 'ReactCoffeeScriptClass', ->
instance = test(React.createElement(Foo), 'DIV', 'foo')
expect(instance.refs.inner.getName()).toBe 'foo'
+ undefined
it 'supports drilling through to the DOM using findDOMNode', ->
instance = test Inner(name: 'foo'), 'DIV', 'foo'
node = ReactDOM.findDOMNode(instance)
expect(node).toBe container.firstChild
+ undefined
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 44298bda154d0..fe6d4910de290 100644
--- a/src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts
+++ b/src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts
@@ -319,8 +319,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`.'
);
@@ -361,15 +361,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'
);
});
@@ -437,19 +437,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.'
);
});
@@ -459,8 +459,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 ' +
@@ -473,8 +473,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()?'
@@ -491,11 +491,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/class/__tests__/setupSpecEquivalenceReporter.js b/src/isomorphic/modern/class/__tests__/setupSpecEquivalenceReporter.js
new file mode 100644
index 0000000000000..90e430f4c7fe5
--- /dev/null
+++ b/src/isomorphic/modern/class/__tests__/setupSpecEquivalenceReporter.js
@@ -0,0 +1,31 @@
+/*!
+ * Copyright 2015-present, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
+ */
+
+'use strict';
+
+var expect = global.expect;
+
+var numExpectations = 0;
+
+global.expect = function() {
+ numExpectations += 1;
+ return expect.apply(this, arguments);
+};
+
+beforeEach(() => numExpectations = 0);
+
+jasmine.currentEnv_.addReporter({
+ specDone: (spec) => {
+ console.log(
+ `EQUIVALENCE: ${spec.description}, ` +
+ `status: ${spec.status}, ` +
+ `numExpectations: ${numExpectations}`
+ );
+ },
+});
diff --git a/src/isomorphic/modern/element/__tests__/ReactJSXElement-test.js b/src/isomorphic/modern/element/__tests__/ReactJSXElement-test.js
index 5adf59d503d4b..2e70b0253eccc 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('overrides children if undefined is provided as an argument', function() {
@@ -136,7 +136,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() {
@@ -153,7 +153,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 c6429dfc24097..827ab73ee505f 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
@@ -196,7 +196,7 @@ describe('ReactJSXElementValidator', function() {
}
ReactTestUtils.renderIntoDocument();
expect(
- console.error.argsForCall[0][0].replace(/\(at .+?:\d+\)/g, '(at **)')
+ console.error.calls.argsFor(0)[0].replace(/\(at .+?:\d+\)/g, '(at **)')
).toBe(
'Warning: Failed prop type: ' +
'Invalid prop `color` of type `number` supplied to `MyComp`, ' +
@@ -217,25 +217,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() {
@@ -245,9 +245,9 @@ describe('ReactJSXElementValidator', function() {
ReactTestUtils.renderIntoDocument();
- expect(console.error.calls.length).toBe(1);
+ expect(console.error.calls.count()).toBe(1);
expect(
- console.error.argsForCall[0][0].replace(/\(at .+?:\d+\)/g, '(at **)')
+ console.error.calls.argsFor(0)[0].replace(/\(at .+?:\d+\)/g, '(at **)')
).toBe(
'Warning: Failed prop type: ' +
'Required prop `prop` was not specified in `RequiredPropComponent`.\n' +
@@ -260,9 +260,9 @@ describe('ReactJSXElementValidator', function() {
ReactTestUtils.renderIntoDocument();
- expect(console.error.calls.length).toBe(1);
+ expect(console.error.calls.count()).toBe(1);
expect(
- console.error.argsForCall[0][0].replace(/\(at .+?:\d+\)/g, '(at **)')
+ console.error.calls.argsFor(0)[0].replace(/\(at .+?:\d+\)/g, '(at **)')
).toBe(
'Warning: Failed prop type: ' +
'Required prop `prop` was not specified in `RequiredPropComponent`.\n' +
@@ -276,9 +276,9 @@ describe('ReactJSXElementValidator', function() {
ReactTestUtils.renderIntoDocument();
ReactTestUtils.renderIntoDocument();
- expect(console.error.calls.length).toBe(2);
+ expect(console.error.calls.count()).toBe(2);
expect(
- console.error.argsForCall[0][0].replace(/\(at .+?:\d+\)/g, '(at **)')
+ console.error.calls.argsFor(0)[0].replace(/\(at .+?:\d+\)/g, '(at **)')
).toBe(
'Warning: Failed prop type: ' +
'Required prop `prop` was not specified in `RequiredPropComponent`.\n' +
@@ -286,7 +286,7 @@ describe('ReactJSXElementValidator', function() {
);
expect(
- console.error.argsForCall[1][0].replace(/\(at .+?:\d+\)/g, '(at **)')
+ console.error.calls.argsFor(1)[0].replace(/\(at .+?:\d+\)/g, '(at **)')
).toBe(
'Warning: Failed prop type: ' +
'Invalid prop `prop` of type `number` supplied to ' +
@@ -297,7 +297,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() {
@@ -315,8 +315,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.'
);
@@ -333,8 +333,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.'
);
@@ -351,8 +351,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 7e68c03eb5393..090207f301c40 100644
--- a/src/renderers/dom/client/wrappers/__tests__/ReactDOMInput-test.js
+++ b/src/renderers/dom/client/wrappers/__tests__/ReactDOMInput-test.js
@@ -329,29 +329,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() {
@@ -407,8 +407,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.'
);
@@ -419,27 +419,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() {
@@ -488,21 +488,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 ' +
@@ -514,14 +514,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 ' +
@@ -533,7 +533,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() {
@@ -541,8 +541,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 ' +
@@ -555,8 +555,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 ' +
@@ -569,8 +569,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 ' +
@@ -583,8 +583,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 ' +
@@ -597,8 +597,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 ' +
@@ -611,8 +611,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 ' +
@@ -625,8 +625,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 ' +
@@ -639,8 +639,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 ' +
@@ -653,8 +653,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 ' +
@@ -668,7 +668,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', {
@@ -677,7 +677,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();
// only warn once
- expect(console.error.calls.length).toBe(1);
- expect(console.error.argsForCall[0][0]).toContain('Only strings and numbers are supported as
A gorilla!
);
- expect(console.error.argsForCall[0][0]).toContain(
+ expect(console.error.calls.argsFor(0)[0]).toContain(
'Select elements must be either controlled or uncontrolled ' +
'(specify either the value prop, or the defaultValue prop, but not ' +
'both). Decide between using a controlled or uncontrolled select ' +
@@ -515,7 +515,7 @@ describe('ReactDOMSelect', function() {
A gorilla!
);
- expect(console.error.argsForCall.length).toBe(1);
+ expect(console.error.calls.count()).toBe(1);
});
it('should be able to safely remove select onChange', function() {
diff --git a/src/renderers/dom/client/wrappers/__tests__/ReactDOMTextarea-test.js b/src/renderers/dom/client/wrappers/__tests__/ReactDOMTextarea-test.js
index 1819efa3523aa..58eeba9dbf09f 100644
--- a/src/renderers/dom/client/wrappers/__tests__/ReactDOMTextarea-test.js
+++ b/src/renderers/dom/client/wrappers/__tests__/ReactDOMTextarea-test.js
@@ -257,7 +257,7 @@ describe('ReactDOMTextarea', function() {
var stub = ;
var node = renderTextarea(stub, container);
- expect(console.error.argsForCall.length).toBe(1);
+ expect(console.error.calls.count()).toBe(1);
expect(node.value).toBe('giraffe');
// Changing children should do nothing, it functions like `defaultValue`.
@@ -296,14 +296,14 @@ describe('ReactDOMTextarea', function() {
it('should allow numbers as children', function() {
spyOn(console, 'error');
var node = renderTextarea();
- expect(console.error.argsForCall.length).toBe(1);
+ expect(console.error.calls.count()).toBe(1);
expect(node.value).toBe('17');
});
it('should allow booleans as children', function() {
spyOn(console, 'error');
var node = renderTextarea();
- expect(console.error.argsForCall.length).toBe(1);
+ expect(console.error.calls.count()).toBe(1);
expect(node.value).toBe('false');
});
@@ -315,7 +315,7 @@ describe('ReactDOMTextarea', function() {
},
};
var node = renderTextarea();
- expect(console.error.argsForCall.length).toBe(1);
+ expect(console.error.calls.count()).toBe(1);
expect(node.value).toBe('sharkswithlasers');
});
@@ -328,7 +328,7 @@ describe('ReactDOMTextarea', function() {
);
}).toThrow();
- expect(console.error.argsForCall.length).toBe(1);
+ expect(console.error.calls.count()).toBe(1);
var node;
expect(function() {
@@ -337,7 +337,7 @@ describe('ReactDOMTextarea', function() {
expect(node.value).toBe('[object Object]');
- expect(console.error.argsForCall.length).toBe(2);
+ expect(console.error.calls.count()).toBe(2);
});
it('should support ReactLink', function() {
@@ -346,8 +346,8 @@ describe('ReactDOMTextarea', function() {
spyOn(console, 'error');
instance = renderTextarea(instance);
- 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 `textarea` is deprecated; set `value` and `onChange` instead.'
);
@@ -373,14 +373,14 @@ describe('ReactDOMTextarea', function() {
spyOn(console, 'error');
ReactTestUtils.renderIntoDocument();
- expect(console.error.argsForCall[0][0]).toContain(
+ expect(console.error.calls.argsFor(0)[0]).toContain(
'`value` prop on `textarea` 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 value and defaultValue are specified', function() {
@@ -388,7 +388,7 @@ describe('ReactDOMTextarea', function() {
ReactTestUtils.renderIntoDocument(
);
- expect(console.error.argsForCall[0][0]).toContain(
+ expect(console.error.calls.argsFor(0)[0]).toContain(
'Textarea elements must be either controlled or uncontrolled ' +
'(specify either the value prop, or the defaultValue prop, but not ' +
'both). Decide between using a controlled or uncontrolled textarea ' +
@@ -399,7 +399,7 @@ describe('ReactDOMTextarea', function() {
ReactTestUtils.renderIntoDocument(
);
- expect(console.error.argsForCall.length).toBe(1);
+ expect(console.error.calls.count()).toBe(1);
});
});
diff --git a/src/renderers/dom/server/__tests__/ReactServerRendering-test.js b/src/renderers/dom/server/__tests__/ReactServerRendering-test.js
index d3919e7b93bec..0ebabbfd67ae2 100644
--- a/src/renderers/dom/server/__tests__/ReactServerRendering-test.js
+++ b/src/renderers/dom/server/__tests__/ReactServerRendering-test.js
@@ -250,7 +250,7 @@ describe('ReactServerRendering', function() {
spyOn(console, 'error');
instance = ReactDOM.render(, element);
expect(mountCount).toEqual(4);
- expect(console.error.argsForCall.length).toBe(1);
+ expect(console.error.calls.count()).toBe(1);
expect(element.innerHTML.length > 0).toBe(true);
expect(element.innerHTML).not.toEqual(lastMarkup);
@@ -266,7 +266,7 @@ describe('ReactServerRendering', function() {
ReactServerRendering,
'not a component'
)
- ).toThrow(
+ ).toThrowError(
'renderToString(): You must pass a valid ReactElement.'
);
});
@@ -375,7 +375,7 @@ describe('ReactServerRendering', function() {
ReactServerRendering,
'not a component'
)
- ).toThrow(
+ ).toThrowError(
'renderToStaticMarkup(): You must pass a valid ReactElement.'
);
});
diff --git a/src/renderers/dom/shared/__tests__/CSSPropertyOperations-test.js b/src/renderers/dom/shared/__tests__/CSSPropertyOperations-test.js
index d33d2e6b1ef50..e7ba52c84366d 100644
--- a/src/renderers/dom/shared/__tests__/CSSPropertyOperations-test.js
+++ b/src/renderers/dom/shared/__tests__/CSSPropertyOperations-test.js
@@ -117,8 +117,8 @@ describe('CSSPropertyOperations', function() {
spyOn(console, 'error');
var root = document.createElement('div');
ReactDOM.render(, root);
- expect(console.error.argsForCall.length).toBe(1);
- expect(console.error.argsForCall[0][0]).toEqual(
+ expect(console.error.calls.count()).toBe(1);
+ expect(console.error.calls.argsFor(0)[0]).toEqual(
'Warning: Unsupported style property background-color. Did you mean backgroundColor? ' +
'Check the render method of `Comp`.'
);
@@ -140,12 +140,12 @@ describe('CSSPropertyOperations', function() {
ReactDOM.render(, root);
ReactDOM.render(, root);
- expect(console.error.argsForCall.length).toBe(2);
- expect(console.error.argsForCall[0][0]).toEqual(
+ expect(console.error.calls.count()).toBe(2);
+ expect(console.error.calls.argsFor(0)[0]).toEqual(
'Warning: Unsupported style property -ms-transform. Did you mean msTransform? ' +
'Check the render method of `Comp`.'
);
- expect(console.error.argsForCall[1][0]).toEqual(
+ expect(console.error.calls.argsFor(1)[0]).toEqual(
'Warning: Unsupported style property -webkit-transform. Did you mean WebkitTransform? ' +
'Check the render method of `Comp`.'
);
@@ -166,12 +166,12 @@ describe('CSSPropertyOperations', function() {
var root = document.createElement('div');
ReactDOM.render(, root);
// msTransform is correct already and shouldn't warn
- expect(console.error.argsForCall.length).toBe(2);
- expect(console.error.argsForCall[0][0]).toEqual(
+ expect(console.error.calls.count()).toBe(2);
+ expect(console.error.calls.argsFor(0)[0]).toEqual(
'Warning: Unsupported vendor-prefixed style property oTransform. ' +
'Did you mean OTransform? Check the render method of `Comp`.'
);
- expect(console.error.argsForCall[1][0]).toEqual(
+ expect(console.error.calls.argsFor(1)[0]).toEqual(
'Warning: Unsupported vendor-prefixed style property webkitTransform. ' +
'Did you mean WebkitTransform? Check the render method of `Comp`.'
);
@@ -192,12 +192,12 @@ describe('CSSPropertyOperations', function() {
spyOn(console, 'error');
var root = document.createElement('div');
ReactDOM.render(, root);
- expect(console.error.calls.length).toBe(2);
- expect(console.error.argsForCall[0][0]).toEqual(
+ expect(console.error.calls.count()).toBe(2);
+ expect(console.error.calls.argsFor(0)[0]).toEqual(
'Warning: Style property values shouldn\'t contain a semicolon. ' +
'Check the render method of `Comp`. Try "backgroundColor: blue" instead.',
);
- expect(console.error.argsForCall[1][0]).toEqual(
+ expect(console.error.calls.argsFor(1)[0]).toEqual(
'Warning: Style property values shouldn\'t contain a semicolon. ' +
'Check the render method of `Comp`. Try "color: red" instead.',
);
@@ -214,8 +214,8 @@ describe('CSSPropertyOperations', function() {
var root = document.createElement('div');
ReactDOM.render(, root);
- expect(console.error.calls.length).toBe(1);
- expect(console.error.argsForCall[0][0]).toEqual(
+ expect(console.error.calls.count()).toBe(1);
+ expect(console.error.calls.argsFor(0)[0]).toEqual(
'Warning: `NaN` is an invalid value for the `fontSize` css style property. ' +
'Check the render method of `Comp`.'
);
diff --git a/src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js b/src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js
index 4200d3767889c..b75eb9bfe23b6 100644
--- a/src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js
+++ b/src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js
@@ -200,8 +200,8 @@ describe('DOMPropertyOperations', function() {
'xlinkHref',
'about:blank'
);
- expect(stubNode.setAttributeNS.argsForCall.length).toBe(1);
- expect(stubNode.setAttributeNS.argsForCall[0])
+ expect(stubNode.setAttributeNS.calls.count()).toBe(1);
+ expect(stubNode.setAttributeNS.calls.argsFor(0))
.toEqual(['http://www.w3.org/1999/xlink', 'xlink:href', 'about:blank']);
});
diff --git a/src/renderers/dom/shared/__tests__/Danger-test.js b/src/renderers/dom/shared/__tests__/Danger-test.js
index 97149d1d1d658..f34cd0b3698c5 100644
--- a/src/renderers/dom/shared/__tests__/Danger-test.js
+++ b/src/renderers/dom/shared/__tests__/Danger-test.js
@@ -78,19 +78,19 @@ describe('Danger', function() {
it('should throw when rendering invalid markup', function() {
expect(function() {
Danger.dangerouslyRenderMarkup(['']);
- }).toThrow(
+ }).toThrowError(
'dangerouslyRenderMarkup(...): Missing markup.'
);
spyOn(console, 'error');
var renderedMarkup = Danger.dangerouslyRenderMarkup(['']);
- var args = console.error.argsForCall[0];
+ var args = console.error.calls.argsFor(0);
expect(renderedMarkup.length).toBe(1);
expect(renderedMarkup[0].nodeName).toBe('P');
- expect(console.error.argsForCall.length).toBe(1);
+ expect(console.error.calls.count()).toBe(1);
expect(args.length).toBe(2);
expect(args[0]).toBe('Danger: Discarding unexpected node:');
diff --git a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
index 5c128e332b3ee..f55475b8c2dcc 100644
--- a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
+++ b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
@@ -128,8 +128,8 @@ describe('ReactDOMComponent', function() {
var stub = ReactTestUtils.renderIntoDocument();
style.position = 'absolute';
stub.setState({style: style});
- expect(console.error.argsForCall.length).toBe(1);
- expect(console.error.argsForCall[0][0]).toEqual(
+ expect(console.error.calls.count()).toBe(1);
+ expect(console.error.calls.argsFor(0)[0]).toEqual(
'Warning: `div` was passed a style object that has previously been ' +
'mutated. Mutating `style` is deprecated. Consider cloning it ' +
'beforehand. Check the `render` of `App`. Previous style: ' +
@@ -142,22 +142,22 @@ describe('ReactDOMComponent', function() {
style.background = 'green';
stub.setState({style: {background: 'green'}});
// already warned once for the same component and owner
- expect(console.error.argsForCall.length).toBe(1);
+ expect(console.error.calls.count()).toBe(1);
style = {background: 'red'};
var div = document.createElement('div');
ReactDOM.render(, div);
style.background = 'blue';
ReactDOM.render(, div);
- expect(console.error.argsForCall.length).toBe(2);
+ expect(console.error.calls.count()).toBe(2);
});
it('should warn for unknown prop', function() {
spyOn(console, 'error');
var container = document.createElement('div');
ReactDOM.render(, container);
- expect(console.error.argsForCall.length).toBe(1);
- expect(normalizeCodeLocInfo(console.error.argsForCall[0][0])).toBe(
+ expect(console.error.calls.count(0)).toBe(1);
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Unknown prop `foo` on
tag. Remove this prop from the element. ' +
'For details, see https://fb.me/react-unknown-prop\n in div (at **)'
);
@@ -180,8 +180,8 @@ describe('ReactDOMComponent', function() {
},
});
ReactDOM.render(, div);
- 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: a `div` tag (owner: `One`) was passed a numeric string value ' +
'for CSS property `fontSize` (value: `1`) which will be treated ' +
'as a unitless number in a future version of React.'
@@ -189,12 +189,12 @@ describe('ReactDOMComponent', function() {
// Don't warn again for the same component
ReactDOM.render(, div);
- expect(console.error.calls.length).toBe(1);
+ expect(console.error.calls.count()).toBe(1);
// Do warn for different components
ReactDOM.render(, div);
- expect(console.error.calls.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: a `div` tag (owner: `Two`) was passed a numeric string value ' +
'for CSS property `fontSize` (value: `1`) which will be treated ' +
'as a unitless number in a future version of React.'
@@ -202,7 +202,7 @@ describe('ReactDOMComponent', function() {
// Really don't warn again for the same component
ReactDOM.render(, div);
- expect(console.error.calls.length).toBe(2);
+ expect(console.error.calls.count()).toBe(2);
});
it('should warn nicely about NaN in style', function() {
@@ -213,8 +213,8 @@ describe('ReactDOMComponent', function() {
ReactDOM.render(, div);
ReactDOM.render(, div);
- expect(console.error.argsForCall.length).toBe(1);
- expect(console.error.argsForCall[0][0]).toEqual(
+ expect(console.error.calls.count()).toBe(1);
+ expect(console.error.calls.argsFor(0)[0]).toEqual(
'Warning: `NaN` is an invalid value for the `fontSize` css style property.',
);
});
@@ -352,8 +352,8 @@ describe('ReactDOMComponent', function() {
);
ReactDOM.render(element, container);
}
- expect(console.error.argsForCall.length).toBe(1);
- expect(console.error.argsForCall[0][0]).toEqual(
+ expect(console.error.calls.count()).toBe(1);
+ expect(console.error.calls.argsFor(0)[0]).toEqual(
'Warning: Invalid attribute name: `blah" onclick="beevil" noise="hi`'
);
});
@@ -372,8 +372,8 @@ describe('ReactDOMComponent', function() {
);
ReactDOM.render(afterUpdate, container);
}
- expect(console.error.argsForCall.length).toBe(1);
- expect(console.error.argsForCall[0][0]).toEqual(
+ expect(console.error.calls.count()).toBe(1);
+ expect(console.error.calls.argsFor(0)[0]).toEqual(
'Warning: Invalid attribute name: `blah" onclick="beevil" noise="hi`'
);
});
@@ -654,27 +654,34 @@ describe('ReactDOMComponent', function() {
);
};
- this.addMatchers({
- toHaveAttribute: function(attr, value) {
- var expected = '(?:^|\\s)' + attr + '=[\\\'"]';
- if (typeof value !== 'undefined') {
- expected += quoteRegexp(value) + '[\\\'"]';
- }
- return this.actual.match(new RegExp(expected));
+ jasmine.addMatchers({
+ toHaveAttribute() {
+ return {
+ compare(actual, expected) {
+ var [attr, value] = expected;
+ var re = '(?:^|\\s)' + attr + '=[\\\'"]';
+ if (typeof value !== 'undefined') {
+ re += quoteRegexp(value) + '[\\\'"]';
+ }
+ return {
+ pass: (new RegExp(re)).test(actual),
+ };
+ },
+ };
},
});
});
it('should generate the correct markup with className', function() {
- expect(genMarkup({className: 'a'})).toHaveAttribute('class', 'a');
- expect(genMarkup({className: 'a b'})).toHaveAttribute('class', 'a b');
- expect(genMarkup({className: ''})).toHaveAttribute('class', '');
+ expect(genMarkup({className: 'a'})).toHaveAttribute(['class', 'a']);
+ expect(genMarkup({className: 'a b'})).toHaveAttribute(['class', 'a b']);
+ expect(genMarkup({className: ''})).toHaveAttribute(['class', '']);
});
it('should escape style names and values', function() {
expect(genMarkup({
style: {'b&ckground': '<3'},
- })).toHaveAttribute('style', 'b&ckground:<3;');
+ })).toHaveAttribute(['style', 'b&ckground:<3;']);
});
});
@@ -704,10 +711,16 @@ describe('ReactDOMComponent', function() {
);
};
- this.addMatchers({
- toHaveInnerhtml: function(html) {
- var expected = '^' + quoteRegexp(html) + '$';
- return this.actual.match(new RegExp(expected));
+ jasmine.addMatchers({
+ toHaveInnerhtml() {
+ return {
+ compare(actual, expected) {
+ var re = '^' + quoteRegexp(expected) + '$';
+ return {
+ pass: (new RegExp(re)).test(actual),
+ };
+ },
+ };
},
});
});
@@ -745,7 +758,7 @@ describe('ReactDOMComponent', function() {
expect(function() {
ReactDOM.render(children, container);
- }).toThrow(
+ }).toThrowError(
'input is a void element tag and must not have `children` or ' +
'use `props.dangerouslySetInnerHTML`.'
);
@@ -759,7 +772,7 @@ describe('ReactDOMComponent', function() {
,
container
);
- }).toThrow(
+ }).toThrowError(
'input is a void element tag and must not have `children` or use ' +
'`props.dangerouslySetInnerHTML`.'
);
@@ -774,7 +787,7 @@ describe('ReactDOMComponent', function() {
expect(function() {
ReactDOM.render(, container);
- }).toThrow(
+ }).toThrowError(
'menuitem is a void element tag and must not have `children` or use ' +
'`props.dangerouslySetInnerHTML`.'
);
@@ -784,7 +797,7 @@ describe('ReactDOMComponent', function() {
it('should validate against multiple children props', function() {
expect(function() {
mountComponent({children: '', dangerouslySetInnerHTML: ''});
- }).toThrow(
+ }).toThrowError(
'Can only set one of `children` or `props.dangerouslySetInnerHTML`.'
);
});
@@ -793,8 +806,8 @@ describe('ReactDOMComponent', function() {
spyOn(console, 'error');
mountComponent({innerHTML: 'Hi Jim!'});
- 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(
'Directly setting property `innerHTML` is not permitted. '
);
});
@@ -802,7 +815,7 @@ describe('ReactDOMComponent', function() {
it('should validate use of dangerouslySetInnerHTML', function() {
expect(function() {
mountComponent({dangerouslySetInnerHTML: 'Hi Jim!'});
- }).toThrow(
+ }).toThrowError(
'`props.dangerouslySetInnerHTML` must be in the form `{__html: ...}`. ' +
'Please visit https://fb.me/react-invariant-dangerously-set-inner-html for more information.'
);
@@ -811,7 +824,7 @@ describe('ReactDOMComponent', function() {
it('should validate use of dangerouslySetInnerHTML', function() {
expect(function() {
mountComponent({dangerouslySetInnerHTML: {foo: 'bar'} });
- }).toThrow(
+ }).toThrowError(
'`props.dangerouslySetInnerHTML` must be in the form `{__html: ...}`. ' +
'Please visit https://fb.me/react-invariant-dangerously-set-inner-html for more information.'
);
@@ -826,20 +839,20 @@ describe('ReactDOMComponent', function() {
it('should warn about contentEditable and children', function() {
spyOn(console, 'error');
mountComponent({contentEditable: true, children: ''});
- expect(console.error.argsForCall.length).toBe(1);
- expect(console.error.argsForCall[0][0]).toContain('contentEditable');
+ expect(console.error.calls.count()).toBe(1);
+ expect(console.error.calls.argsFor(0)[0]).toContain('contentEditable');
});
it('should respect suppressContentEditableWarning', function() {
spyOn(console, 'error');
mountComponent({contentEditable: true, children: '', suppressContentEditableWarning: true});
- expect(console.error.argsForCall.length).toBe(0);
+ expect(console.error.calls.count()).toBe(0);
});
it('should validate against invalid styles', function() {
expect(function() {
mountComponent({style: 'display: none'});
- }).toThrow(
+ }).toThrowError(
'The `style` prop expects a mapping from style properties to values, ' +
'not a string. For example, style={{marginRight: spacing + \'em\'}} ' +
'when using JSX.'
@@ -929,7 +942,7 @@ describe('ReactDOMComponent', function() {
var container = document.createElement('div');
expect(function() {
ReactDOM.render(, container);
- }).toThrow(
+ }).toThrowError(
'input is a void element tag and must not have `children` ' +
'or use `props.dangerouslySetInnerHTML`. Check the render method of X.'
);
@@ -938,7 +951,7 @@ describe('ReactDOMComponent', function() {
it('should support custom elements which extend native elements', function() {
if (ReactDOMFeatureFlags.useCreateElement) {
var container = document.createElement('div');
- spyOn(document, 'createElement').andCallThrough();
+ spyOn(document, 'createElement').and.callThrough();
ReactDOM.render(, container);
expect(document.createElement).toHaveBeenCalledWith('div', 'custom-div');
} else {
@@ -959,7 +972,7 @@ describe('ReactDOMComponent', function() {
expect(function() {
ReactDOM.render(children, container);
- }).toThrow(
+ }).toThrowError(
'input is a void element tag and must not have `children` or use ' +
'`props.dangerouslySetInnerHTML`.'
);
@@ -973,7 +986,7 @@ describe('ReactDOMComponent', function() {
,
container
);
- }).toThrow(
+ }).toThrowError(
'input is a void element tag and must not have `children` or use ' +
'`props.dangerouslySetInnerHTML`.'
);
@@ -987,7 +1000,7 @@ describe('ReactDOMComponent', function() {
,
container
);
- }).toThrow(
+ }).toThrowError(
'Can only set one of `children` or `props.dangerouslySetInnerHTML`.'
);
});
@@ -998,8 +1011,8 @@ describe('ReactDOMComponent', function() {
,
container
);
- expect(console.error.argsForCall.length).toBe(1);
- expect(console.error.argsForCall[0][0]).toContain('contentEditable');
+ expect(console.error.calls.count()).toBe(1);
+ expect(console.error.calls.argsFor(0)[0]).toContain('contentEditable');
});
it('should validate against invalid styles', function() {
@@ -1007,7 +1020,7 @@ describe('ReactDOMComponent', function() {
expect(function() {
ReactDOM.render(, container);
- }).toThrow(
+ }).toThrowError(
'The `style` prop expects a mapping from style properties to values, ' +
'not a string. For example, style={{marginRight: spacing + \'em\'}} ' +
'when using JSX.'
@@ -1023,7 +1036,7 @@ describe('ReactDOMComponent', function() {
expect(function() {
ReactDOM.render(, container);
- }).toThrow(
+ }).toThrowError(
'The `style` prop expects a mapping from style properties to values, ' +
'not a string. For example, style={{marginRight: spacing + \'em\'}} ' +
'when using JSX. This DOM node was rendered by `Animal`.'
@@ -1083,7 +1096,7 @@ describe('ReactDOMComponent', function() {
ReactDOM.unmountComponentAtNode(container);
- expect(tracker.stopTracking.calls.length).toBe(1);
+ expect(tracker.stopTracking.calls.count()).toBe(1);
});
it('should clean up input textarea tracking', function() {
@@ -1095,7 +1108,7 @@ describe('ReactDOMComponent', function() {
ReactDOM.unmountComponentAtNode(container);
- expect(tracker.stopTracking.calls.length).toBe(1);
+ expect(tracker.stopTracking.calls.count()).toBe(1);
});
it('unmounts children before unsetting DOM node info', function() {
@@ -1128,8 +1141,8 @@ describe('ReactDOMComponent', function() {
spyOn(console, 'error');
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: This browser doesn\'t support the `onScroll` event'
);
});
@@ -1147,7 +1160,7 @@ describe('ReactDOMComponent', function() {
var hackzor = React.createElement('script tag');
expect(
() => ReactTestUtils.renderIntoDocument(hackzor)
- ).toThrow(
+ ).toThrowError(
'Invalid tag: script tag'
);
});
@@ -1157,7 +1170,7 @@ describe('ReactDOMComponent', function() {
var hackzor = React.createElement('div>
. See Foo > table > Row > tr. Add a to your code to ' +
'match the DOM tree generated by the browser.'
);
- expect(console.error.argsForCall[1][0]).toBe(
+ expect(console.error.calls.argsFor(1)[0]).toBe(
'Warning: validateDOMNesting(...): #text cannot appear as a child ' +
'of