Merge pull request #6872 from gaearon/jest-cli@12

Update to Jest 12.1.1 and Jasmine 2
(cherry picked from commit c0ecde687a)
This commit is contained in:
Dan Abramov
2016-06-14 15:49:43 -07:00
committed by Paul O’Shannessy
parent 58313419e2
commit c8b2a3dc13
66 changed files with 832 additions and 903 deletions
+7 -2
View File
@@ -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);
+1 -2
View File
@@ -55,7 +55,7 @@
"gulp-flatten": "^0.2.0",
"gulp-util": "^3.0.7",
"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",
@@ -90,7 +90,6 @@
"scriptPreprocessor": "scripts/jest/preprocessor.js",
"setupEnvScriptFile": "scripts/jest/environment.js",
"setupTestFrameworkScriptFile": "scripts/jest/test-framework-setup.js",
"testRunner": "jasmine1",
"testFileExtensions": [
"coffee",
"js",
+1
View File
@@ -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
+39 -24
View File
@@ -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.
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();
});
+11 -11
View File
@@ -31,7 +31,7 @@ describe('ReactFragment', function() {
};
var element = <div>{[children]}</div>;
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(<Foo />, container)).toThrow(
expect(() => ReactDOM.render(<Foo />, 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(<div>{oldEl}</div>, container)).toThrow(
expect(() => ReactDOM.render(<div>{oldEl}</div>, 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: <span />, 2: <span />});
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(<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(
'React.addons.createFragment does not accept a ReactElement without a ' +
'wrapper object.'
);
@@ -88,7 +88,7 @@ describe('renderSubtreeIntoContainer', function() {
componentDidMount: function() {
expect(function() {
renderSubtreeIntoContainer(<Parent />, <Component />, portal);
}).toThrow('parentComponentmust be a valid React Component');
}).toThrowError('parentComponentmust be a valid React Component');
},
});
});
+11 -11
View File
@@ -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: ...}?'
@@ -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);
@@ -286,14 +286,14 @@ describe('ReactTransitionGroup', function() {
ReactDOM.render(<Component />, 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, ' +
@@ -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 = <div>{simpleKid}</div>;
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(<span key=".$simple" />);
});
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 = <div>{simpleKid}</div>;
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(<span key=".0" />);
});
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 = <div>{[simpleKid]}</div>;
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(<span key=".$simple" />);
@@ -124,7 +124,7 @@ describe('ReactChildren', function() {
<span />, // Map from null to something.
<div key="keyFour" />,
];
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 = <div key="keyFour" />;
var fiveMapped = <div />;
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);
@@ -149,8 +149,8 @@ describe('ReactContextValidator', function() {
ReactTestUtils.renderIntoDocument(<Component />);
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(<ComponentInFooNumberContext fooValue={123} />);
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(<Component testContext={{bar: 123}} />);
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(<Component testContext={{foo: 123}} />);
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);
});
});
@@ -132,8 +132,8 @@ describe('autobinding', function() {
ReactTestUtils.renderIntoDocument(<TestBindComponent />);
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(<TestBindComponent />);
expect(console.error.argsForCall.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
});
});
@@ -203,7 +203,7 @@ describe('autobind optout', function() {
ReactTestUtils.renderIntoDocument(<TestBindComponent />);
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(<TestBindComponent />);
expect(console.error.argsForCall.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
});
});
@@ -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 <span>{this.props.prop}</span>;
},
});
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 <span>{this.props.prop}</span>;
},
});
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 <span>{this.props.prop}</span>;
},
});
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 <div />;
},
});
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 <div />;
},
});
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 <div />;
},
});
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 <span />;
},
});
}).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 <div />;
},
});
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 = <Component />;
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'
);
@@ -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 = <Component />;
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 <span />;
},
});
}).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 <span />;
},
});
}).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 <span />;
},
});
}).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 <span />;
},
});
}).toThrow(
}).toThrowError(
'ReactClass: You\'re attempting to use a component class or function ' +
'as a mixin. Instead, just use a regular object.'
);
@@ -76,10 +76,10 @@ describe('ReactElement', function() {
);
},
});
expect(console.error.calls.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
ReactDOM.render(<Parent />, 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(<Parent />, 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(<Test value={+undefined} />);
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
@@ -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(<div />, null, [<div />, <div />]);
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(<div />, null, [<div key="#1" />, <div key="#2" />]);
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(<div />, null, <div />, <div />);
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(<div />, 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' +
@@ -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(<Anonymous>{divs}</Anonymous>);
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(<div>{divs}</div>);
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 <div>. See ' +
'https://fb.me/react-warning-keys for more information.\n' +
@@ -147,8 +147,8 @@ describe('ReactElementValidator', function() {
ReactTestUtils.renderIntoDocument(<GrandParent />);
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() {
</Wrapper>
);
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(<DOMContainer>{node}</DOMContainer>);
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 <Foo>{[<div />]}</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: 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).'
@@ -271,7 +271,7 @@ describe('ReactPropTypes', function() {
var instance = <Component label={<div />} />;
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 = <Component />;
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 = <Component num={5} />;
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 = <Component bla={5} />;
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 = <Component num={6} />;
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 = <Component num={5} />;
instance = ReactTestUtils.renderIntoDocument(instance);
expect(console.error.argsForCall.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
}
);
});
@@ -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);
}
@@ -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
@@ -61,8 +61,8 @@ describe('ReactES6Class', function() {
class Foo extends React.Component { }
expect(() => ReactDOM.render(<Foo />, 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 <span />;
}
}
expect(() => test(<Foo />, 'span', '')).toThrow(
expect(() => test(<Foo />, 'span', '')).toThrowError(
'Foo.state: must be set to an object or null'
);
});
@@ -339,17 +339,17 @@ describe('ReactES6Class', function() {
test(<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.'
);
});
@@ -367,8 +367,8 @@ describe('ReactES6Class', function() {
}
test(<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 ' +
@@ -389,8 +389,8 @@ describe('ReactES6Class', function() {
}
test(<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()?'
@@ -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'
);
});
@@ -319,8 +319,8 @@ describe('ReactTypeScriptClass', function() {
expect(() => ReactDOM.render(React.createElement(Empty), container)).toThrow();
expect((<any>console.error).argsForCall.length).toBe(1);
expect((<any>console.error).argsForCall[0][0]).toBe(
expect((<any>console.error).calls.count()).toBe(1);
expect((<any>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((<any>console.error).argsForCall.length).toBe(4);
expect((<any>console.error).argsForCall[0][0]).toContain(
expect((<any>console.error).calls.count()).toBe(4);
expect((<any>console.error).calls.argsFor(0)[0]).toContain(
'getInitialState was defined on ClassicProperties, ' +
'a plain JavaScript class.'
);
expect((<any>console.error).argsForCall[1][0]).toContain(
expect((<any>console.error).calls.argsFor(1)[0]).toContain(
'getDefaultProps was defined on ClassicProperties, ' +
'a plain JavaScript class.'
);
expect((<any>console.error).argsForCall[2][0]).toContain(
expect((<any>console.error).calls.argsFor(2)[0]).toContain(
'propTypes was defined as an instance property on ClassicProperties.'
);
expect((<any>console.error).argsForCall[3][0]).toContain(
expect((<any>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((<any>console.error).argsForCall.length).toBe(1);
expect((<any>console.error).argsForCall[0][0]).toBe(
expect((<any>console.error).calls.count()).toBe(1);
expect((<any>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((<any>console.error).argsForCall.length).toBe(1);
expect((<any>console.error).argsForCall[0][0]).toBe(
expect((<any>console.error).calls.count()).toBe(1);
expect((<any>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((<any>console.error).argsForCall.length).toBe(2);
expect((<any>console.error).argsForCall[0][0]).toContain(
expect((<any>console.error).calls.count()).toBe(2);
expect((<any>console.error).calls.argsFor(0)[0]).toContain(
'replaceState(...) is deprecated in plain JavaScript React classes'
);
expect((<any>console.error).argsForCall[1][0]).toContain(
expect((<any>console.error).calls.argsFor(1)[0]).toContain(
'isMounted(...) is deprecated in plain JavaScript React classes'
);
});
@@ -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}`
);
},
});
@@ -100,21 +100,21 @@ describe('ReactJSXElement', function() {
var a = 1;
var element = <Component children="text">{a}</Component>;
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 = <Component 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 a JSX child', function() {
spyOn(console, 'error');
var element = <Component children="text">{null}</Component>;
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 = <Component>{a}{b}{c}</Component>;
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 = <StaticMethodComponent />;
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() {
@@ -47,8 +47,8 @@ describe('ReactJSXElementValidator', function() {
void <Component>{[<Component />, <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('ReactJSXElementValidator', function() {
ReactTestUtils.renderIntoDocument(<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 `InnerComponent`. ' +
'It was passed a child from ComponentWrapper. '
@@ -99,8 +99,8 @@ describe('ReactJSXElementValidator', function() {
void <Component>{iterable}</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.'
);
});
@@ -110,7 +110,7 @@ describe('ReactJSXElementValidator', function() {
void <Component>{[<Component key="#1" />, <Component key="#2" />]}</Component>;
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 <Component>{iterable}</Component>;
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 <Component>{iterable}</Component>;
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 <Component><Component /><Component /></Component>;
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 <Component>{[{}, {}]}</Component>;
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(<ParentComp />);
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 <Null />;
void <True />;
void <Num />;
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 <Div />;
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(<RequiredPropComponent />);
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(<RequiredPropComponent prop={null} />);
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(<RequiredPropComponent />);
ReactTestUtils.renderIntoDocument(<RequiredPropComponent prop={42} />);
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(<RequiredPropComponent prop="string" />);
// 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(<NullPropTypeComponent />);
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(<NullContextTypeComponent />);
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(<GetDefaultPropsComponent />);
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.'
);
@@ -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 <div>{[<span />]}</div>;
expect(console.error.argsForCall.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
});
it('should handle a simple flow', function() {
@@ -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]);
}
@@ -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(<A />, myDiv, 'no')).toThrow(
expect(() => ReactDOM.render(<A />, myDiv, 'no')).toThrowError(
'ReactDOM.render(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: string.'
);
expect(() => ReactDOM.render(<A />, myDiv, {})).toThrow(
expect(() => ReactDOM.render(<A />, myDiv, {})).toThrowError(
'ReactDOM.render(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: Object.'
);
expect(() => ReactDOM.render(<A />, myDiv, new Foo())).toThrow(
expect(() => ReactDOM.render(<A />, 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(<A />, myDiv);
expect(() => ReactDOM.render(<A />, myDiv, 'no')).toThrow(
expect(() => ReactDOM.render(<A />, myDiv, 'no')).toThrowError(
'ReactDOM.render(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: string.'
);
expect(() => ReactDOM.render(<A />, myDiv, {})).toThrow(
expect(() => ReactDOM.render(<A />, myDiv, {})).toThrowError(
'ReactDOM.render(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: Object.'
);
expect(() => ReactDOM.render(<A />, myDiv, new Foo())).toThrow(
expect(() => ReactDOM.render(<A />, myDiv, new Foo())).toThrowError(
'ReactDOM.render(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: Foo (keys: a, b).'
);
@@ -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 <div />.'
);
@@ -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 <Foo />.'
);
@@ -133,12 +133,12 @@ describe('ReactMount', function() {
spyOn(console, 'error');
ReactMount.render(<div />, container);
expect(console.error.calls.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
container.innerHTML = ' ' + ReactDOMServer.renderToString(<div />);
ReactMount.render(<div />, 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(<div />, 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(<div />, 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() {
<div>This markup contains an nbsp entity: &nbsp; client text</div>,
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: &nbsp; client text</div>\n' +
' (server) nbsp entity: &nbsp; server text</div>'
);
@@ -217,8 +217,8 @@ describe('ReactMount', function() {
spyOn(console, 'error');
var rootNode = container.firstChild;
ReactDOM.render(<span />, 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(<Foo />);
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;
}
@@ -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 ' +
@@ -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(<Component2 />, 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(<Component text="Hello world" />, 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(<Component />, 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 ' +
@@ -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(<Foo />, container);
ReactDOM.unmountComponentAtNode(container);
expect(() => ReactDOM.findDOMNode(inst)).toThrow(
expect(() => ReactDOM.findDOMNode(inst)).toThrowError(
'findDOMNode was called on an unmounted component.'
);
});
@@ -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(<div onClick={assignEvent} />, 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);
}
});
});
@@ -320,29 +320,29 @@ describe('ReactDOMInput', function() {
it('should warn with value and no onChange handler', function() {
var link = new ReactLink('yolo', jest.fn());
ReactTestUtils.renderIntoDocument(<input type="text" valueLink={link} />);
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(
<input type="text" value="zoink" onChange={jest.fn()} />
);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
ReactTestUtils.renderIntoDocument(<input type="text" value="zoink" />);
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(
<input type="text" value="zoink" readOnly={true} />
);
expect(console.error.argsForCall.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
ReactTestUtils.renderIntoDocument(
<input type="text" value="zoink" readOnly={false} />
);
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() {
@@ -398,8 +398,8 @@ describe('ReactDOMInput', function() {
var node = document.createElement('div');
var link = new ReactLink(true, jest.fn());
ReactDOM.render(<input type="checkbox" checkedLink={link} />, 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.'
);
@@ -410,27 +410,27 @@ describe('ReactDOMInput', function() {
onChange={jest.fn()}
/>
);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
ReactTestUtils.renderIntoDocument(
<input type="checkbox" checked="false" readOnly={true} />
);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
ReactTestUtils.renderIntoDocument(<input type="checkbox" checked="false" />);
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(
<input type="checkbox" checked="false" readOnly={true} />
);
expect(console.error.argsForCall.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
ReactTestUtils.renderIntoDocument(
<input type="checkbox" checked="false" readOnly={false} />
);
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() {
@@ -479,21 +479,21 @@ describe('ReactDOMInput', function() {
it('should warn if value is null', function() {
ReactTestUtils.renderIntoDocument(<input type="text" value={null} />);
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(<input type="text" value={null} />);
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(
<input type="radio" checked={true} defaultChecked={true} readOnly={true} />
);
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 ' +
@@ -505,14 +505,14 @@ describe('ReactDOMInput', function() {
ReactTestUtils.renderIntoDocument(
<input type="radio" checked={true} defaultChecked={true} readOnly={true} />
);
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(
<input type="text" value="foo" defaultValue="bar" readOnly={true} />
);
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 ' +
@@ -524,7 +524,7 @@ describe('ReactDOMInput', function() {
ReactTestUtils.renderIntoDocument(
<input type="text" value="foo" defaultValue="bar" readOnly={true} />
);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
});
it('should warn if controlled input switches to uncontrolled', function() {
@@ -532,8 +532,8 @@ describe('ReactDOMInput', function() {
var container = document.createElement('div');
ReactDOM.render(stub, container);
ReactDOM.render(<input type="text" />, 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 ' +
@@ -546,8 +546,8 @@ describe('ReactDOMInput', function() {
var container = document.createElement('div');
ReactDOM.render(stub, container);
ReactDOM.render(<input type="text" defaultValue="uncontrolled" />, 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 ' +
@@ -560,8 +560,8 @@ describe('ReactDOMInput', function() {
var container = document.createElement('div');
ReactDOM.render(stub, container);
ReactDOM.render(<input type="text" value="controlled" />, 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 ' +
@@ -574,8 +574,8 @@ describe('ReactDOMInput', function() {
var container = document.createElement('div');
ReactDOM.render(stub, container);
ReactDOM.render(<input type="checkbox" />, 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 ' +
@@ -588,8 +588,8 @@ describe('ReactDOMInput', function() {
var container = document.createElement('div');
ReactDOM.render(stub, container);
ReactDOM.render(<input type="checkbox" defaultChecked={true} />, 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 ' +
@@ -602,8 +602,8 @@ describe('ReactDOMInput', function() {
var container = document.createElement('div');
ReactDOM.render(stub, container);
ReactDOM.render(<input type="checkbox" checked={true} />, 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 ' +
@@ -616,8 +616,8 @@ describe('ReactDOMInput', function() {
var container = document.createElement('div');
ReactDOM.render(stub, container);
ReactDOM.render(<input type="radio" />, 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 ' +
@@ -630,8 +630,8 @@ describe('ReactDOMInput', function() {
var container = document.createElement('div');
ReactDOM.render(stub, container);
ReactDOM.render(<input type="radio" defaultChecked={true} />, 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 ' +
@@ -644,8 +644,8 @@ describe('ReactDOMInput', function() {
var container = document.createElement('div');
ReactDOM.render(stub, container);
ReactDOM.render(<input type="radio" checked={true} />, 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 ' +
@@ -659,7 +659,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', {
@@ -668,7 +668,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);
});
}
@@ -39,8 +39,8 @@ describe('ReactDOMOption', function() {
expect(node.innerHTML).toBe('1 2');
ReactTestUtils.renderIntoDocument(<option>{1} <div /> {2}</option>);
// only warn once
expect(console.error.calls.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain('Only strings and numbers are supported as <option> children.');
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain('Only strings and numbers are supported as <option> children.');
});
it('should ignore null/undefined/false children without warning', function() {
@@ -50,7 +50,7 @@ describe('ReactDOMOption', function() {
var node = ReactDOM.findDOMNode(stub);
expect(console.error.calls.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
expect(node.innerHTML).toBe('1 2');
});
@@ -93,5 +93,5 @@ describe('ReactDOMOption', function() {
container
);
expect(node.selectedIndex).toEqual(2);
});
});
});
@@ -360,8 +360,8 @@ describe('ReactDOMSelect', function() {
stub = ReactTestUtils.renderIntoDocument(stub);
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 `select` is deprecated; set `value` and `onChange` instead.'
);
@@ -466,14 +466,14 @@ describe('ReactDOMSelect', function() {
spyOn(console, 'error');
ReactTestUtils.renderIntoDocument(<select value={null}><option value="test"/></select>);
expect(console.error.argsForCall[0][0]).toContain(
expect(console.error.calls.argsFor(0)[0]).toContain(
'`value` prop on `select` should not be null. ' +
'Consider using the empty string to clear the component or `undefined` ' +
'for uncontrolled components.'
);
ReactTestUtils.renderIntoDocument(<select value={null}><option value="test"/></select>);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
});
it('should refresh state on change', function() {
@@ -500,7 +500,7 @@ describe('ReactDOMSelect', function() {
<option value="gorilla">A gorilla!</option>
</select>
);
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() {
<option value="gorilla">A gorilla!</option>
</select>
);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
});
it('should be able to safely remove select onChange', function() {
@@ -257,7 +257,7 @@ describe('ReactDOMTextarea', function() {
var stub = <textarea>giraffe</textarea>;
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(<textarea>{17}</textarea>);
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(<textarea>{false}</textarea>);
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(<textarea>{obj}</textarea>);
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(<textarea value={null} />);
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(<textarea value={null} />);
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(
<textarea value="foo" defaultValue="bar" readOnly={true} />
);
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(
<textarea value="foo" defaultValue="bar" readOnly={true} />
);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
});
});
@@ -250,7 +250,7 @@ describe('ReactServerRendering', function() {
spyOn(console, 'error');
instance = ReactDOM.render(<TestComponent name="y" />, 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.'
);
});
@@ -117,8 +117,8 @@ describe('CSSPropertyOperations', function() {
spyOn(console, 'error');
var root = document.createElement('div');
ReactDOM.render(<Comp />, 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(<Comp />, root);
ReactDOM.render(<Comp style={styles} />, 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(<Comp />, 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(<Comp />, 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(<Comp />, 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`.'
);
@@ -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']);
});
@@ -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(['<p></p><p></p>']);
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:');
@@ -126,8 +126,8 @@ describe('ReactDOMComponent', function() {
var stub = ReactTestUtils.renderIntoDocument(<App />);
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: ' +
@@ -140,22 +140,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(<span style={style}></span>, div);
style.background = 'blue';
ReactDOM.render(<span style={style}></span>, 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(<div foo="bar" />, 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 <div> tag. Remove this prop from the element. ' +
'For details, see https://fb.me/react-unknown-prop\n in div (at **)'
);
@@ -178,8 +178,8 @@ describe('ReactDOMComponent', function() {
},
});
ReactDOM.render(<One inline={false} />, 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.'
@@ -187,12 +187,12 @@ describe('ReactDOMComponent', function() {
// Don't warn again for the same component
ReactDOM.render(<One inline={true} />, div);
expect(console.error.calls.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
// Do warn for different components
ReactDOM.render(<Two />, 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.'
@@ -200,7 +200,7 @@ describe('ReactDOMComponent', function() {
// Really don't warn again for the same component
ReactDOM.render(<One inline={true} />, div);
expect(console.error.calls.length).toBe(2);
expect(console.error.calls.count()).toBe(2);
});
it('should warn nicely about NaN in style', function() {
@@ -211,8 +211,8 @@ describe('ReactDOMComponent', function() {
ReactDOM.render(<span style={style}></span>, div);
ReactDOM.render(<span style={style}></span>, 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.',
);
});
@@ -350,8 +350,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`'
);
});
@@ -370,8 +370,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`'
);
});
@@ -652,27 +652,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&amp;ckground:&lt;3;');
})).toHaveAttribute(['style', 'b&amp;ckground:&lt;3;']);
});
});
@@ -702,10 +709,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),
};
},
};
},
});
});
@@ -743,7 +756,7 @@ describe('ReactDOMComponent', function() {
expect(function() {
ReactDOM.render(<input>children</input>, container);
}).toThrow(
}).toThrowError(
'input is a void element tag and must not have `children` or ' +
'use `props.dangerouslySetInnerHTML`.'
);
@@ -757,7 +770,7 @@ describe('ReactDOMComponent', function() {
<input dangerouslySetInnerHTML={{__html: 'content'}} />,
container
);
}).toThrow(
}).toThrowError(
'input is a void element tag and must not have `children` or use ' +
'`props.dangerouslySetInnerHTML`.'
);
@@ -772,7 +785,7 @@ describe('ReactDOMComponent', function() {
expect(function() {
ReactDOM.render(<menu><menuitem>children</menuitem></menu>, container);
}).toThrow(
}).toThrowError(
'menuitem is a void element tag and must not have `children` or use ' +
'`props.dangerouslySetInnerHTML`.'
);
@@ -782,7 +795,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`.'
);
});
@@ -791,8 +804,8 @@ describe('ReactDOMComponent', function() {
spyOn(console, 'error');
mountComponent({innerHTML: '<span>Hi Jim!</span>'});
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. '
);
});
@@ -800,7 +813,7 @@ describe('ReactDOMComponent', function() {
it('should validate use of dangerouslySetInnerHTML', function() {
expect(function() {
mountComponent({dangerouslySetInnerHTML: '<span>Hi Jim!</span>'});
}).toThrow(
}).toThrowError(
'`props.dangerouslySetInnerHTML` must be in the form `{__html: ...}`. ' +
'Please visit https://fb.me/react-invariant-dangerously-set-inner-html for more information.'
);
@@ -809,7 +822,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.'
);
@@ -824,20 +837,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.'
@@ -909,7 +922,7 @@ describe('ReactDOMComponent', function() {
var container = document.createElement('div');
expect(function() {
ReactDOM.render(<X />, container);
}).toThrow(
}).toThrowError(
'input is a void element tag and must not have `children` ' +
'or use `props.dangerouslySetInnerHTML`. Check the render method of X.'
);
@@ -918,7 +931,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(<div is="custom-div" />, container);
expect(document.createElement).toHaveBeenCalledWith('div', 'custom-div');
} else {
@@ -939,7 +952,7 @@ describe('ReactDOMComponent', function() {
expect(function() {
ReactDOM.render(<input>children</input>, container);
}).toThrow(
}).toThrowError(
'input is a void element tag and must not have `children` or use ' +
'`props.dangerouslySetInnerHTML`.'
);
@@ -953,7 +966,7 @@ describe('ReactDOMComponent', function() {
<input dangerouslySetInnerHTML={{__html: 'content'}} />,
container
);
}).toThrow(
}).toThrowError(
'input is a void element tag and must not have `children` or use ' +
'`props.dangerouslySetInnerHTML`.'
);
@@ -967,7 +980,7 @@ describe('ReactDOMComponent', function() {
<div children="" dangerouslySetInnerHTML={{__html: ''}}></div>,
container
);
}).toThrow(
}).toThrowError(
'Can only set one of `children` or `props.dangerouslySetInnerHTML`.'
);
});
@@ -978,8 +991,8 @@ describe('ReactDOMComponent', function() {
<div contentEditable={true}><div /></div>,
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() {
@@ -987,7 +1000,7 @@ describe('ReactDOMComponent', function() {
expect(function() {
ReactDOM.render(<div style={1}></div>, 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.'
@@ -1003,7 +1016,7 @@ describe('ReactDOMComponent', function() {
expect(function() {
ReactDOM.render(<Animal/>, 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`.'
@@ -1084,8 +1097,8 @@ describe('ReactDOMComponent', function() {
spyOn(console, 'error');
ReactTestUtils.renderIntoDocument(<div onScroll={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 browser doesn\'t support the `onScroll` event'
);
});
@@ -1103,7 +1116,7 @@ describe('ReactDOMComponent', function() {
var hackzor = React.createElement('script tag');
expect(
() => ReactTestUtils.renderIntoDocument(hackzor)
).toThrow(
).toThrowError(
'Invalid tag: script tag'
);
});
@@ -1113,7 +1126,7 @@ describe('ReactDOMComponent', function() {
var hackzor = React.createElement('div><img /><div');
expect(
() => ReactTestUtils.renderIntoDocument(hackzor)
).toThrow(
).toThrowError(
'Invalid tag: div><img /><div'
);
});
@@ -1130,8 +1143,8 @@ describe('ReactDOMComponent', function() {
spyOn(console, 'error');
ReactTestUtils.renderIntoDocument(<div><tr /><tr /></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: validateDOMNesting(...): <tr> cannot appear as a child of ' +
'<div>. See div > tr.'
);
@@ -1142,8 +1155,8 @@ describe('ReactDOMComponent', function() {
var p = document.createElement('p');
ReactDOM.render(<span><p /></span>, p);
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: validateDOMNesting(...): <p> cannot appear as a descendant ' +
'of <p>. See p > ... > p.'
);
@@ -1163,13 +1176,13 @@ describe('ReactDOMComponent', function() {
});
ReactTestUtils.renderIntoDocument(<Foo />);
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: validateDOMNesting(...): <tr> cannot appear as a child of ' +
'<table>. See Foo > table > Row > tr. Add a <tbody> 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 <table>. See Foo > table > #text.'
);
@@ -1201,8 +1214,8 @@ describe('ReactDOMComponent', function() {
render: () => <Viz1 />,
});
ReactTestUtils.renderIntoDocument(<App1 />);
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(
'See Viz1 > table > FancyRow > Row > tr.'
);
@@ -1213,26 +1226,26 @@ describe('ReactDOMComponent', function() {
render: () => <Viz2 />,
});
ReactTestUtils.renderIntoDocument(<App2 />);
expect(console.error.calls.length).toBe(2);
expect(console.error.argsForCall[1][0]).toContain(
expect(console.error.calls.count()).toBe(2);
expect(console.error.calls.argsFor(1)[0]).toContain(
'See Viz2 > FancyTable > Table > table > FancyRow > Row > tr.'
);
ReactTestUtils.renderIntoDocument(<FancyTable><FancyRow /></FancyTable>);
expect(console.error.calls.length).toBe(3);
expect(console.error.argsForCall[2][0]).toContain(
expect(console.error.calls.count()).toBe(3);
expect(console.error.calls.argsFor(2)[0]).toContain(
'See FancyTable > Table > table > FancyRow > Row > tr.'
);
ReactTestUtils.renderIntoDocument(<table><FancyRow /></table>);
expect(console.error.calls.length).toBe(4);
expect(console.error.argsForCall[3][0]).toContain(
expect(console.error.calls.count()).toBe(4);
expect(console.error.calls.argsFor(3)[0]).toContain(
'See table > FancyRow > Row > tr.'
);
ReactTestUtils.renderIntoDocument(<FancyTable><tr /></FancyTable>);
expect(console.error.calls.length).toBe(5);
expect(console.error.argsForCall[4][0]).toContain(
expect(console.error.calls.count()).toBe(5);
expect(console.error.calls.argsFor(4)[0]).toContain(
'See FancyTable > Table > table > tr.'
);
@@ -1242,8 +1255,8 @@ describe('ReactDOMComponent', function() {
},
});
ReactTestUtils.renderIntoDocument(<Link><div><Link /></div></Link>);
expect(console.error.calls.length).toBe(6);
expect(console.error.argsForCall[5][0]).toContain(
expect(console.error.calls.count()).toBe(6);
expect(console.error.calls.argsFor(5)[0]).toContain(
'See Link > a > ... > Link > a.'
);
});
@@ -1251,66 +1264,66 @@ describe('ReactDOMComponent', function() {
it('should warn about incorrect casing on properties (ssr)', function() {
spyOn(console, 'error');
ReactDOMServer.renderToString(React.createElement('input', {type: 'text', tabindex: '1'}));
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain('tabIndex');
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain('tabIndex');
});
it('should warn about incorrect casing on event handlers (ssr)', function() {
spyOn(console, 'error');
ReactDOMServer.renderToString(React.createElement('input', {type: 'text', onclick: '1'}));
ReactDOMServer.renderToString(React.createElement('input', {type: 'text', onKeydown: '1'}));
expect(console.error.argsForCall.length).toBe(2);
expect(console.error.argsForCall[0][0]).toContain('onClick');
expect(console.error.argsForCall[1][0]).toContain('onKeyDown');
expect(console.error.calls.count()).toBe(2);
expect(console.error.calls.argsFor(0)[0]).toContain('onClick');
expect(console.error.calls.argsFor(1)[0]).toContain('onKeyDown');
});
it('should warn about incorrect casing on properties', function() {
spyOn(console, 'error');
ReactTestUtils.renderIntoDocument(React.createElement('input', {type: 'text', tabindex: '1'}));
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain('tabIndex');
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain('tabIndex');
});
it('should warn about incorrect casing on event handlers', function() {
spyOn(console, 'error');
ReactTestUtils.renderIntoDocument(React.createElement('input', {type: 'text', onclick: '1'}));
ReactTestUtils.renderIntoDocument(React.createElement('input', {type: 'text', onKeydown: '1'}));
expect(console.error.argsForCall.length).toBe(2);
expect(console.error.argsForCall[0][0]).toContain('onClick');
expect(console.error.argsForCall[1][0]).toContain('onKeyDown');
expect(console.error.calls.count()).toBe(2);
expect(console.error.calls.argsFor(0)[0]).toContain('onClick');
expect(console.error.calls.argsFor(1)[0]).toContain('onKeyDown');
});
it('should warn about class', function() {
spyOn(console, 'error');
ReactDOMServer.renderToString(React.createElement('div', {class: 'muffins'}));
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain('className');
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain('className');
});
it('should warn about props that are no longer supported', function() {
spyOn(console, 'error');
ReactTestUtils.renderIntoDocument(<div />);
expect(console.error.argsForCall.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
ReactTestUtils.renderIntoDocument(<div onFocusIn={() => {}} />);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
ReactTestUtils.renderIntoDocument(<div onFocusOut={() => {}} />);
expect(console.error.argsForCall.length).toBe(2);
expect(console.error.calls.count()).toBe(2);
});
it('gives source code refs for unknown prop warning', function() {
spyOn(console, 'error');
ReactDOMServer.renderToString(<div class="paladin"/>);
ReactDOMServer.renderToString(<input type="text" onclick="1"/>);
expect(console.error.argsForCall.length).toBe(2);
expect(console.error.calls.count()).toBe(2);
expect(
normalizeCodeLocInfo(console.error.argsForCall[0][0])
normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])
).toBe(
'Warning: Unknown DOM property class. Did you mean className?\n in div (at **)'
);
expect(
normalizeCodeLocInfo(console.error.argsForCall[1][0])
normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])
).toBe(
'Warning: Unknown event handler property onclick. Did you mean ' +
'`onClick`?\n in input (at **)'
@@ -1322,12 +1335,12 @@ describe('ReactDOMComponent', function() {
var container = document.createElement('div');
ReactDOMServer.renderToString(<div className="paladin" />, container);
expect(console.error.argsForCall.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
ReactDOMServer.renderToString(<div class="paladin" />, container);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
expect(
normalizeCodeLocInfo(console.error.argsForCall[0][0])
normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])
).toBe(
'Warning: Unknown DOM property class. Did you mean className?\n in div (at **)'
);
@@ -1347,14 +1360,14 @@ describe('ReactDOMComponent', function() {
</div>
);
expect(console.error.argsForCall.length).toBe(2);
expect(console.error.calls.count()).toBe(2);
expect(console.error.argsForCall[0][0]).toContain('className');
var matches = console.error.argsForCall[0][0].match(/.*\(.*:(\d+)\).*/);
expect(console.error.calls.argsFor(0)[0]).toContain('className');
var matches = console.error.calls.argsFor(0)[0].match(/.*\(.*:(\d+)\).*/);
var previousLine = matches[1];
expect(console.error.argsForCall[1][0]).toContain('onClick');
matches = console.error.argsForCall[1][0].match(/.*\(.*:(\d+)\).*/);
expect(console.error.calls.argsFor(1)[0]).toContain('onClick');
matches = console.error.calls.argsFor(1)[0].match(/.*\(.*:(\d+)\).*/);
var currentLine = matches[1];
//verify line number has a proper relative difference,
@@ -1398,14 +1411,14 @@ describe('ReactDOMComponent', function() {
ReactDOMServer.renderToString(<Parent />, container);
expect(console.error.argsForCall.length).toBe(2);
expect(console.error.calls.count()).toBe(2);
expect(console.error.argsForCall[0][0]).toContain('className');
var matches = console.error.argsForCall[0][0].match(/.*\(.*:(\d+)\).*/);
expect(console.error.calls.argsFor(0)[0]).toContain('className');
var matches = console.error.calls.argsFor(0)[0].match(/.*\(.*:(\d+)\).*/);
var previousLine = matches[1];
expect(console.error.argsForCall[1][0]).toContain('onClick');
matches = console.error.argsForCall[1][0].match(/.*\(.*:(\d+)\).*/);
expect(console.error.calls.argsFor(1)[0]).toContain('onClick');
matches = console.error.calls.argsFor(1)[0].match(/.*\(.*:(\d+)\).*/);
var currentLine = matches[1];
//verify line number has a proper relative difference,
@@ -27,31 +27,31 @@ describe('ReactDOMDebugTool', function() {
ReactDOMDebugTool.addDevtool(devtool1);
ReactDOMDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(1);
expect(handler2.calls.length).toBe(0);
expect(handler1.calls.count()).toBe(1);
expect(handler2.calls.count()).toBe(0);
ReactDOMDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(2);
expect(handler2.calls.length).toBe(0);
expect(handler1.calls.count()).toBe(2);
expect(handler2.calls.count()).toBe(0);
ReactDOMDebugTool.addDevtool(devtool2);
ReactDOMDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(3);
expect(handler2.calls.length).toBe(1);
expect(handler1.calls.count()).toBe(3);
expect(handler2.calls.count()).toBe(1);
ReactDOMDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(4);
expect(handler2.calls.length).toBe(2);
expect(handler1.calls.count()).toBe(4);
expect(handler2.calls.count()).toBe(2);
ReactDOMDebugTool.removeDevtool(devtool1);
ReactDOMDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(4);
expect(handler2.calls.length).toBe(3);
expect(handler1.calls.count()).toBe(4);
expect(handler2.calls.count()).toBe(3);
ReactDOMDebugTool.removeDevtool(devtool2);
ReactDOMDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(4);
expect(handler2.calls.length).toBe(3);
expect(handler1.calls.count()).toBe(4);
expect(handler2.calls.count()).toBe(3);
});
it('warns once when an error is thrown in devtool', () => {
@@ -63,13 +63,13 @@ describe('ReactDOMDebugTool', function() {
});
ReactDOMDebugTool.onTestEvent();
expect(console.error.calls.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain(
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'exception thrown by devtool while handling ' +
'onTestEvent: Error: Hi.'
);
ReactDOMDebugTool.onTestEvent();
expect(console.error.calls.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
});
});
@@ -27,31 +27,31 @@ describe('ReactDebugTool', function() {
ReactDebugTool.addDevtool(devtool1);
ReactDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(1);
expect(handler2.calls.length).toBe(0);
expect(handler1.calls.count()).toBe(1);
expect(handler2.calls.count()).toBe(0);
ReactDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(2);
expect(handler2.calls.length).toBe(0);
expect(handler1.calls.count()).toBe(2);
expect(handler2.calls.count()).toBe(0);
ReactDebugTool.addDevtool(devtool2);
ReactDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(3);
expect(handler2.calls.length).toBe(1);
expect(handler1.calls.count()).toBe(3);
expect(handler2.calls.count()).toBe(1);
ReactDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(4);
expect(handler2.calls.length).toBe(2);
expect(handler1.calls.count()).toBe(4);
expect(handler2.calls.count()).toBe(2);
ReactDebugTool.removeDevtool(devtool1);
ReactDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(4);
expect(handler2.calls.length).toBe(3);
expect(handler1.calls.count()).toBe(4);
expect(handler2.calls.count()).toBe(3);
ReactDebugTool.removeDevtool(devtool2);
ReactDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(4);
expect(handler2.calls.length).toBe(3);
expect(handler1.calls.count()).toBe(4);
expect(handler2.calls.count()).toBe(3);
});
it('warns once when an error is thrown in devtool', () => {
@@ -63,14 +63,14 @@ describe('ReactDebugTool', function() {
});
ReactDebugTool.onTestEvent();
expect(console.error.calls.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain(
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'exception thrown by devtool while handling ' +
'onTestEvent: Error: Hi.'
);
ReactDebugTool.onTestEvent();
expect(console.error.calls.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
});
it('returns isProfiling state', () => {
@@ -389,28 +389,28 @@ describe('ReactPerf', function() {
var measurements = measure(() => {});
spyOn(console, 'error');
ReactPerf.getMeasurementsSummaryMap(measurements);
expect(console.error.calls.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain(
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'`ReactPerf.getMeasurementsSummaryMap(...)` is deprecated. Use ' +
'`ReactPerf.getWasted(...)` instead.'
);
ReactPerf.getMeasurementsSummaryMap(measurements);
expect(console.error.calls.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
});
it('warns once when using printDOM', function() {
var measurements = measure(() => {});
spyOn(console, 'error');
ReactPerf.printDOM(measurements);
expect(console.error.calls.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain(
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'`ReactPerf.printDOM(...)` is deprecated. Use ' +
'`ReactPerf.printOperations(...)` instead.'
);
ReactPerf.printDOM(measurements);
expect(console.error.calls.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
});
it('returns isRunning state', () => {
@@ -29,7 +29,7 @@ describe('EventPluginHub', function() {
it('should prevent non-function listeners', function() {
expect(function() {
EventPluginHub.putListener(1, 'onClick', 'not a function');
}).toThrow(
}).toThrowError(
'Expected onClick listener to be a function, instead got type string'
);
});
@@ -95,7 +95,7 @@ describe('EventPluginRegistry', function() {
EventPluginRegistry.injectEventPluginsByName({
bad: BadPlugin,
});
}).toThrow(
}).toThrowError(
'EventPluginRegistry: Event plugins must implement an `extractEvents` ' +
'method, but `bad` does not.'
);
@@ -112,7 +112,7 @@ describe('EventPluginRegistry', function() {
one: OnePlugin,
random: RandomPlugin,
});
}).toThrow(
}).toThrowError(
'EventPluginRegistry: Cannot inject event plugins that do not exist ' +
'in the plugin ordering, `random`.'
);
@@ -125,7 +125,7 @@ describe('EventPluginRegistry', function() {
expect(function() {
EventPluginRegistry.injectEventPluginOrder(pluginOrdering);
}).toThrow(
}).toThrowError(
'EventPluginRegistry: Cannot inject event plugin ordering more than ' +
'once. You are likely trying to load more than one copy of React.'
);
@@ -139,7 +139,7 @@ describe('EventPluginRegistry', function() {
expect(function() {
EventPluginRegistry.injectEventPluginsByName({same: TwoPlugin});
}).toThrow(
}).toThrowError(
'EventPluginRegistry: Cannot inject two different event plugins using ' +
'the same name, `same`.'
);
@@ -203,7 +203,7 @@ describe('EventPluginRegistry', function() {
expect(function() {
EventPluginRegistry.injectEventPluginOrder(['one', 'two']);
}).toThrow(
}).toThrowError(
'EventPluginHub: More than one plugin attempted to publish the same ' +
'registration name, `onPhotoCapture`.'
);
@@ -220,7 +220,7 @@ describe('EventPluginRegistry', function() {
expect(function() {
EventPluginRegistry.injectEventPluginOrder(['one']);
}).toThrow(
}).toThrowError(
'EventPluginRegistry: Failed to publish event `badEvent` for plugin ' +
'`one`.'
);
@@ -40,8 +40,8 @@ describe('ReactChildReconciler', function() {
ReactTestUtils.renderIntoDocument(<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(
'Child keys must be unique; when two children share a key, only the first child will be used.'
);
});
@@ -69,8 +69,8 @@ describe('ReactChildReconciler', function() {
ReactTestUtils.renderIntoDocument(<GrandParent />);
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: flattenChildren(...): ' +
'Encountered two children with the same key, `1`. ' +
'Child keys must be unique; when two children share a key, ' +
@@ -27,13 +27,13 @@ describe('ReactComponent', function() {
// jQuery objects are basically arrays; people often pass them in by mistake
expect(function() {
ReactDOM.render(<div></div>, [container]);
}).toThrow(
}).toThrowError(
'_registerComponent(...): Target container is not a DOM element.'
);
expect(function() {
ReactDOM.render(<div></div>, null);
}).toThrow(
}).toThrowError(
'_registerComponent(...): Target container is not a DOM element.'
);
});
@@ -269,25 +269,25 @@ describe('ReactComponent', function() {
spyOn(console, 'error');
var X = undefined;
expect(() => ReactTestUtils.renderIntoDocument(<X />)).toThrow(
expect(() => ReactTestUtils.renderIntoDocument(<X />)).toThrowError(
'Element type is invalid: expected a string (for built-in components) ' +
'or a class/function (for composite components) but got: undefined.'
);
var Y = null;
expect(() => ReactTestUtils.renderIntoDocument(<Y />)).toThrow(
expect(() => ReactTestUtils.renderIntoDocument(<Y />)).toThrowError(
'Element type is invalid: expected a string (for built-in components) ' +
'or a class/function (for composite components) but got: null.'
);
var Z = {};
expect(() => ReactTestUtils.renderIntoDocument(<Z />)).toThrow(
expect(() => ReactTestUtils.renderIntoDocument(<Z />)).toThrowError(
'Element type is invalid: expected a string (for built-in components) ' +
'or a class/function (for composite components) but got: object.'
);
// One warning for each element creation
expect(console.error.calls.length).toBe(3);
expect(console.error.calls.count()).toBe(3);
});
});
@@ -224,8 +224,8 @@ describe('ReactComponentLifeCycle', function() {
},
});
ReactTestUtils.renderIntoDocument(<StatefulComponent />);
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: setState(...): Can only update a mounted or ' +
'mounting component. This usually means you called setState() on an ' +
'unmounted component. This is a no-op. Please check the code for the ' +
@@ -253,8 +253,8 @@ describe('ReactComponentLifeCycle', function() {
var instance = ReactTestUtils.renderIntoDocument(element);
expect(instance.isMounted()).toBeTruthy();
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(
'Component is accessing isMounted inside its render()'
);
});
@@ -279,8 +279,8 @@ describe('ReactComponentLifeCycle', function() {
var instance = ReactTestUtils.renderIntoDocument(element);
expect(instance.isMounted()).toBeTruthy();
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(
'Component is accessing isMounted inside its render()'
);
});
@@ -320,8 +320,8 @@ describe('ReactComponentLifeCycle', function() {
});
ReactTestUtils.renderIntoDocument(<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(
'Component is accessing findDOMNode inside its render()'
);
});
@@ -199,11 +199,11 @@ describe('ReactCompositeComponent', function() {
mountedInstance.methodAutoBound();
}).not.toThrow();
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
var explicitlyBound = mountedInstance.methodToBeExplicitlyBound.bind(
mountedInstance
);
expect(console.error.argsForCall.length).toBe(2);
expect(console.error.calls.count()).toBe(2);
var autoBound = mountedInstance.methodAutoBound;
var context = {};
@@ -289,13 +289,13 @@ describe('ReactCompositeComponent', function() {
instance = ReactDOM.render(instance, container);
instance.forceUpdate();
expect(console.error.calls.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
ReactDOM.unmountComponentAtNode(container);
instance.forceUpdate();
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: forceUpdate(...): Can only update a mounted or ' +
'mounting component. This usually means you called forceUpdate() on an ' +
'unmounted component. This is a no-op. Please check the code for the ' +
@@ -330,7 +330,7 @@ describe('ReactCompositeComponent', function() {
instance.setState({value: 1});
expect(console.error.calls.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
expect(renders).toBe(2);
@@ -339,8 +339,8 @@ describe('ReactCompositeComponent', function() {
expect(renders).toBe(2);
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: setState(...): Can only update a mounted or ' +
'mounting component. This usually means you called setState() on an ' +
'unmounted component. This is a no-op. Please check the code for the ' +
@@ -399,12 +399,12 @@ describe('ReactCompositeComponent', function() {
},
});
expect(console.error.calls.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
var instance = ReactDOM.render(<Component />, container);
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: setState(...): Cannot update during an existing state ' +
'transition (such as within `render` or another component\'s ' +
'constructor). Render methods should be a pure function of props and ' +
@@ -447,12 +447,12 @@ describe('ReactCompositeComponent', function() {
return <div />;
},
});
expect(console.error.calls.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
var instance = ReactDOM.render(<Component />, container);
expect(renderPasses).toBe(2);
expect(instance.state.value).toBe(1);
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: setState(...): Cannot call setState() inside getChildContext()'
);
});
@@ -522,8 +522,8 @@ describe('ReactCompositeComponent', function() {
var instance = ReactTestUtils.renderIntoDocument(<Component />);
instance.setState({bogus: true});
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.shouldComponentUpdate(): Returned undefined instead of a ' +
'boolean value. Make sure to return true or false.'
);
@@ -543,8 +543,8 @@ describe('ReactCompositeComponent', function() {
ReactTestUtils.renderIntoDocument(<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: Component has a method called ' +
'componentDidUnmount(). But there is no such lifecycle method. ' +
'Did you mean componentWillUnmount()?'
@@ -1053,8 +1053,8 @@ describe('ReactCompositeComponent', function() {
});
ReactTestUtils.renderIntoDocument(<Outer />);
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: _renderNewRootComponent(): Render methods should ' +
'be a pure function of props and state; triggering nested component ' +
'updates from render is not allowed. If necessary, trigger nested ' +
@@ -1291,12 +1291,12 @@ describe('ReactCompositeComponent', function() {
}
}
expect(console.error.calls.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
ReactDOM.render(<Foo idx="qwe" />, 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(
'Foo(...): When calling super() in `Foo`, make sure to pass ' +
'up the same props that your component\'s constructor was passed.'
);
@@ -78,7 +78,7 @@ describe('ReactEmptyComponent', function() {
});
expect(function() {
ReactTestUtils.renderIntoDocument(<Component />);
}).toThrow(
}).toThrowError(
'Component.render(): A valid React element (or null) must be returned. You may ' +
'have returned undefined, an array or some other invalid object.'
);
@@ -99,11 +99,11 @@ describe('ReactEmptyComponent', function() {
ReactTestUtils.renderIntoDocument(instance1);
ReactTestUtils.renderIntoDocument(instance2);
expect(log.argsForCall.length).toBe(4);
expect(log.argsForCall[0][0]).toBe(null);
expect(log.argsForCall[1][0].tagName).toBe('DIV');
expect(log.argsForCall[2][0].tagName).toBe('DIV');
expect(log.argsForCall[3][0]).toBe(null);
expect(log.calls.count()).toBe(4);
expect(log.calls.argsFor(0)[0]).toBe(null);
expect(log.calls.argsFor(1)[0].tagName).toBe('DIV');
expect(log.calls.argsFor(2)[0].tagName).toBe('DIV');
expect(log.calls.argsFor(3)[0]).toBe(null);
});
it('should be able to switch in a list of children', () => {
@@ -121,13 +121,13 @@ describe('ReactEmptyComponent', function() {
</div>
);
expect(log.argsForCall.length).toBe(6);
expect(log.argsForCall[0][0]).toBe(null);
expect(log.argsForCall[1][0]).toBe(null);
expect(log.argsForCall[2][0]).toBe(null);
expect(log.argsForCall[3][0].tagName).toBe('DIV');
expect(log.argsForCall[4][0].tagName).toBe('DIV');
expect(log.argsForCall[5][0].tagName).toBe('DIV');
expect(log.calls.count()).toBe(6);
expect(log.calls.argsFor(0)[0]).toBe(null);
expect(log.calls.argsFor(1)[0]).toBe(null);
expect(log.calls.argsFor(2)[0]).toBe(null);
expect(log.calls.argsFor(3)[0].tagName).toBe('DIV');
expect(log.calls.argsFor(4)[0].tagName).toBe('DIV');
expect(log.calls.argsFor(5)[0].tagName).toBe('DIV');
});
it('should distinguish between a script placeholder and an actual script tag',
@@ -150,11 +150,11 @@ describe('ReactEmptyComponent', function() {
ReactTestUtils.renderIntoDocument(instance2);
}).not.toThrow();
expect(log.argsForCall.length).toBe(4);
expect(log.argsForCall[0][0]).toBe(null);
expect(log.argsForCall[1][0].tagName).toBe('SCRIPT');
expect(log.argsForCall[2][0].tagName).toBe('SCRIPT');
expect(log.argsForCall[3][0]).toBe(null);
expect(log.calls.count()).toBe(4);
expect(log.calls.argsFor(0)[0]).toBe(null);
expect(log.calls.argsFor(1)[0].tagName).toBe('SCRIPT');
expect(log.calls.argsFor(2)[0].tagName).toBe('SCRIPT');
expect(log.calls.argsFor(3)[0]).toBe(null);
}
);
@@ -191,11 +191,11 @@ describe('ReactEmptyComponent', function() {
ReactTestUtils.renderIntoDocument(instance2);
}).not.toThrow();
expect(log.argsForCall.length).toBe(4);
expect(log.argsForCall[0][0].tagName).toBe('DIV');
expect(log.argsForCall[1][0]).toBe(null);
expect(log.argsForCall[2][0]).toBe(null);
expect(log.argsForCall[3][0].tagName).toBe('DIV');
expect(log.calls.count()).toBe(4);
expect(log.calls.argsFor(0)[0].tagName).toBe('DIV');
expect(log.calls.argsFor(1)[0]).toBe(null);
expect(log.calls.argsFor(2)[0]).toBe(null);
expect(log.calls.argsFor(3)[0].tagName).toBe('DIV');
}
);
@@ -247,7 +247,7 @@ describe('ReactEmptyComponent', function() {
var div = document.createElement('div');
expect(function() {
ReactDOM.render(null, div);
}).toThrow(
}).toThrowError(
'ReactDOM.render(): Invalid component element.'
);
});
@@ -32,7 +32,7 @@ describe('ReactMockedComponent', function() {
it('should allow an implicitly mocked component to be rendered without warnings', () => {
spyOn(console, 'error');
ReactTestUtils.renderIntoDocument(<AutoMockedComponent />);
expect(console.error.calls.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
});
it('should allow an implicitly mocked component to be updated', () => {
@@ -185,8 +185,8 @@ describe('ReactMultiChild', function() {
container
);
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: flattenChildren(...): ' +
'Encountered two children with the same key, `1`. ' +
'Child keys must be unique; when two children share a key, ' +
@@ -273,7 +273,7 @@ describe('ReactMultiChildReconcile', function() {
statusDisplays = parentInstance.getStatusDisplays();
expect(statusDisplays.jcw).toBeTruthy();
expect(statusDisplays.jcw.getInternalState())
.toNotBe(startingInternalState);
.not.toBe(startingInternalState);
});
it('should create unique identity', function() {
@@ -183,8 +183,8 @@ describe('ReactMultiChildText', function() {
[true, <div>{1.2}{''}{<div />}{'foo'}</div>, true, 1.2], [<div />, '1.2'],
['', 'foo', <div>{true}{<div />}{1.2}{''}</div>, 'foo'], ['', 'foo', <div />, 'foo'],
]);
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(
'Warning: Each child in an array or iterator should have a unique "key" prop.'
);
});
@@ -244,6 +244,6 @@ describe('ReactMultiChildText', function() {
expect(childNodes[5]).toBe(alpha3);
// Using Maps as children gives a single warning
expect(console.error.calls.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
});
});
@@ -106,8 +106,8 @@ describe('ReactStatelessComponent', function() {
expect(function() {
ReactTestUtils.renderIntoDocument(<div><NotAComponent /></div>);
}).toThrow();
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(
'NotAComponent(...): A valid React element (or null) must be returned. ' +
'You may have returned undefined, an array or some other invalid object.'
);
@@ -120,7 +120,7 @@ describe('ReactStatelessComponent', function() {
expect(function() {
ReactTestUtils.renderIntoDocument(<Child test="test" />);
}).toThrow(
}).toThrowError(
'Stateless function components cannot have refs.'
);
});
@@ -136,8 +136,8 @@ describe('ReactStatelessComponent', function() {
});
ReactTestUtils.renderIntoDocument(<Parent/>);
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(
'Stateless function components cannot be given refs ' +
'(See ref "stateless" in StatelessComponent created by Parent). ' +
'Attempts to access this ref will fail.'
@@ -160,9 +160,9 @@ describe('ReactStatelessComponent', function() {
spyOn(console, 'error');
ReactTestUtils.renderIntoDocument(<Child />);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain('a unique "key" prop');
expect(console.error.argsForCall[0][0]).toContain('Child');
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain('a unique "key" prop');
expect(console.error.calls.argsFor(0)[0]).toContain('Child');
});
it('should support default props and prop types', function() {
@@ -174,9 +174,9 @@ describe('ReactStatelessComponent', function() {
spyOn(console, 'error');
ReactTestUtils.renderIntoDocument(<Child />);
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: Invalid prop `test` of type `number` ' +
'supplied to `Child`, expected `string`.\n' +
@@ -239,8 +239,8 @@ describe('ReactStatelessComponent', function() {
expect(function() {
ReactTestUtils.renderIntoDocument(<div><NotAComponent /></div>);
}).toThrow(); // has no method 'render'
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(
'NotAComponent(...): A valid React element (or null) must be returned. You may ' +
'have returned undefined, an array or some other invalid object.'
);
@@ -495,7 +495,7 @@ describe('ReactUpdates', function() {
it('should share reconcile transaction across different roots', function() {
var ReconcileTransaction = ReactUpdates.ReactReconcileTransaction;
spyOn(ReconcileTransaction, 'getPooled').andCallThrough();
spyOn(ReconcileTransaction, 'getPooled').and.callThrough();
var Component = React.createClass({
render: function() {
@@ -511,7 +511,7 @@ describe('ReactUpdates', function() {
ReactDOM.render(<Component text="A1" />, containerA);
ReactDOM.render(<Component text="B1" />, containerB);
});
expect(ReconcileTransaction.getPooled.calls.length).toBe(2);
expect(ReconcileTransaction.getPooled.calls.count()).toBe(2);
// ...but updates are! Here only one more transaction is used, which means
// we only have to initialize and close the wrappers once.
@@ -519,7 +519,7 @@ describe('ReactUpdates', function() {
ReactDOM.render(<Component text="A2" />, containerA);
ReactDOM.render(<Component text="B2" />, containerB);
});
expect(ReconcileTransaction.getPooled.calls.length).toBe(3);
expect(ReconcileTransaction.getPooled.calls.count()).toBe(3);
});
it('should queue mount-ready handlers across different roots', function() {
@@ -929,10 +929,10 @@ describe('ReactUpdates', function() {
ReactDOM.render(<Foo />, container);
expect(console.time.argsForCall.length).toBe(1);
expect(console.time.argsForCall[0][0]).toBe('React update: Foo');
expect(console.timeEnd.argsForCall.length).toBe(1);
expect(console.timeEnd.argsForCall[0][0]).toBe('React update: Foo');
expect(console.time.calls.count()).toBe(1);
expect(console.time.calls.argsFor(0)[0]).toBe('React update: Foo');
expect(console.timeEnd.calls.count()).toBe(1);
expect(console.timeEnd.calls.argsFor(0)[0]).toBe('React update: Foo');
} finally {
ReactFeatureFlags.logTopLevelRenders = false;
}
@@ -953,15 +953,15 @@ describe('ReactUpdates', function() {
});
var component = ReactTestUtils.renderIntoDocument(<A />);
expect(() => component.setState({}, 'no')).toThrow(
expect(() => component.setState({}, 'no')).toThrowError(
'setState(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: string.'
);
expect(() => component.setState({}, {})).toThrow(
expect(() => component.setState({}, {})).toThrowError(
'setState(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: Object.'
);
expect(() => component.setState({}, new Foo())).toThrow(
expect(() => component.setState({}, new Foo())).toThrowError(
'setState(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: Foo (keys: a, b).'
);
@@ -982,15 +982,15 @@ describe('ReactUpdates', function() {
});
var component = ReactTestUtils.renderIntoDocument(<A />);
expect(() => component.replaceState({}, 'no')).toThrow(
expect(() => component.replaceState({}, 'no')).toThrowError(
'replaceState(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: string.'
);
expect(() => component.replaceState({}, {})).toThrow(
expect(() => component.replaceState({}, {})).toThrowError(
'replaceState(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: Object.'
);
expect(() => component.replaceState({}, new Foo())).toThrow(
expect(() => component.replaceState({}, new Foo())).toThrowError(
'replaceState(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: Foo (keys: a, b).'
);
@@ -1011,15 +1011,15 @@ describe('ReactUpdates', function() {
});
var component = ReactTestUtils.renderIntoDocument(<A />);
expect(() => component.forceUpdate('no')).toThrow(
expect(() => component.forceUpdate('no')).toThrowError(
'forceUpdate(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: string.'
);
expect(() => component.forceUpdate({})).toThrow(
expect(() => component.forceUpdate({})).toThrowError(
'forceUpdate(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: Object.'
);
expect(() => component.forceUpdate(new Foo())).toThrow(
expect(() => component.forceUpdate(new Foo())).toThrowError(
'forceUpdate(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: Foo (keys: a, b).'
);
@@ -110,7 +110,7 @@ describe('Pooled class', function() {
PoolableClass.getPooled();
expect(function() {
PoolableClass.release(randomInstance);
}).toThrow(
}).toThrowError(
'Trying to release an instance into a pool of a different type.'
);
}
@@ -236,7 +236,7 @@ describe('Transaction', function() {
var transaction = new TestTransaction();
expect(function() {
transaction.perform(function() {});
}).toThrow(exceptionMsg);
}).toThrowError(exceptionMsg);
expect(transaction.isInTransaction()).toBe(false);
});
@@ -25,7 +25,7 @@ describe('accumulateInto', function() {
it('throws if the second item is null', function() {
expect(function() {
accumulateInto([], null);
}).toThrow(
}).toThrowError(
'accumulateInto(...): Accumulated items must not be null or undefined.'
);
});
@@ -29,7 +29,7 @@ describe('traverseAllChildren', function() {
it('should support identity for simple', function() {
var traverseContext = [];
var traverseFn =
jasmine.createSpy().andCallFake(function(context, kid, key, index) {
jasmine.createSpy().and.callFake(function(context, kid, key, index) {
context.push(true);
});
@@ -49,7 +49,7 @@ describe('traverseAllChildren', function() {
it('should treat single arrayless child as being in array', function() {
var traverseContext = [];
var traverseFn =
jasmine.createSpy().andCallFake(function(context, kid, key, index) {
jasmine.createSpy().and.callFake(function(context, kid, key, index) {
context.push(true);
});
@@ -68,7 +68,7 @@ describe('traverseAllChildren', function() {
spyOn(console, 'error');
var traverseContext = [];
var traverseFn =
jasmine.createSpy().andCallFake(function(context, kid, key, index) {
jasmine.createSpy().and.callFake(function(context, kid, key, index) {
context.push(true);
});
@@ -81,8 +81,8 @@ describe('traverseAllChildren', function() {
'.0'
);
expect(traverseContext.length).toEqual(1);
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(
'Warning: Each child in an array or iterator should have a unique "key" prop.'
);
});
@@ -96,7 +96,7 @@ describe('traverseAllChildren', function() {
var traverseContext = [];
var traverseFn =
jasmine.createSpy().andCallFake(function(context, kid, key, index) {
jasmine.createSpy().and.callFake(function(context, kid, key, index) {
context.push(true);
});
@@ -137,7 +137,7 @@ describe('traverseAllChildren', function() {
var traverseContext = [];
var traverseFn =
jasmine.createSpy().andCallFake(function(context, kid, key, index) {
jasmine.createSpy().and.callFake(function(context, kid, key, index) {
context.push(true);
});
@@ -157,7 +157,7 @@ describe('traverseAllChildren', function() {
traverseAllChildren(instance.props.children, traverseFn, traverseContext);
expect(traverseFn.calls.length).toBe(9);
expect(traverseFn.calls.count()).toBe(9);
expect(traverseContext.length).toEqual(9);
expect(traverseFn).toHaveBeenCalledWith(
@@ -205,7 +205,7 @@ describe('traverseAllChildren', function() {
var traverseContext = [];
var traverseFn =
jasmine.createSpy().andCallFake(function(context, kid, key, index) {
jasmine.createSpy().and.callFake(function(context, kid, key, index) {
context.push(true);
});
@@ -222,7 +222,7 @@ describe('traverseAllChildren', function() {
);
traverseAllChildren(instance.props.children, traverseFn, traverseContext);
expect(traverseFn.calls.length).toBe(4);
expect(traverseFn.calls.count()).toBe(4);
expect(traverseContext.length).toEqual(4);
expect(traverseFn).toHaveBeenCalledWith(
traverseContext,
@@ -254,7 +254,7 @@ describe('traverseAllChildren', function() {
var oneForceKey = <div key="keyOne" />;
var traverseContext = [];
var traverseFn =
jasmine.createSpy().andCallFake(function(context, kid, key, index) {
jasmine.createSpy().and.callFake(function(context, kid, key, index) {
context.push(true);
});
@@ -298,7 +298,7 @@ describe('traverseAllChildren', function() {
var traverseContext = [];
var traverseFn =
jasmine.createSpy().andCallFake(function(context, kid, key, index) {
jasmine.createSpy().and.callFake(function(context, kid, key, index) {
context.push(kid);
});
@@ -309,7 +309,7 @@ describe('traverseAllChildren', function() {
);
traverseAllChildren(instance.props.children, traverseFn, traverseContext);
expect(traverseFn.calls.length).toBe(3);
expect(traverseFn.calls.count()).toBe(3);
expect(traverseFn).toHaveBeenCalledWith(
traverseContext,
@@ -327,8 +327,8 @@ describe('traverseAllChildren', function() {
'.2'
);
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(
'Warning: Each child in an array or iterator should have a unique "key" prop.'
);
});
@@ -351,7 +351,7 @@ describe('traverseAllChildren', function() {
var traverseContext = [];
var traverseFn =
jasmine.createSpy().andCallFake(function(context, kid, key, index) {
jasmine.createSpy().and.callFake(function(context, kid, key, index) {
context.push(kid);
});
@@ -362,7 +362,7 @@ describe('traverseAllChildren', function() {
);
traverseAllChildren(instance.props.children, traverseFn, traverseContext);
expect(traverseFn.calls.length).toBe(3);
expect(traverseFn.calls.count()).toBe(3);
expect(traverseFn).toHaveBeenCalledWith(
traverseContext,
@@ -402,7 +402,7 @@ describe('traverseAllChildren', function() {
var traverseContext = [];
var traverseFn =
jasmine.createSpy().andCallFake(function(context, kid, key, index) {
jasmine.createSpy().and.callFake(function(context, kid, key, index) {
context.push(kid);
});
@@ -413,7 +413,7 @@ describe('traverseAllChildren', function() {
);
traverseAllChildren(instance.props.children, traverseFn, traverseContext);
expect(traverseFn.calls.length).toBe(3);
expect(traverseFn.calls.count()).toBe(3);
expect(traverseFn).toHaveBeenCalledWith(
traverseContext,
@@ -431,8 +431,8 @@ describe('traverseAllChildren', function() {
'.$#3:0'
);
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(
'Warning: Using Maps as children is not yet fully supported. It is an ' +
'experimental feature that might be removed. Convert it to a sequence ' +
'/ iterable of keyed ReactElements instead.'
@@ -458,7 +458,7 @@ describe('traverseAllChildren', function() {
var traverseFn = jasmine.createSpy();
traverseAllChildren(instance.props.children, traverseFn, null);
expect(traverseFn.calls.length).toBe(3);
expect(traverseFn.calls.count()).toBe(3);
expect(traverseFn).toHaveBeenCalledWith(
null,
@@ -496,7 +496,7 @@ describe('traverseAllChildren', function() {
var traverseFn = jasmine.createSpy();
traverseAllChildren(instance.props.children, traverseFn, null);
expect(traverseFn.calls.length).toBe(2);
expect(traverseFn.calls.count()).toBe(2);
expect(traverseFn).toHaveBeenCalledWith(
null,
@@ -516,7 +516,7 @@ describe('traverseAllChildren', function() {
it('should throw on object', function() {
expect(function() {
traverseAllChildren({a: 1, b: 2}, function() {}, null);
}).toThrow(
}).toThrowError(
'Objects are not valid as a React child (found: object with keys ' +
'{a, b}). If you meant to render a collection of children, use an ' +
'array instead or wrap the object using createFragment(object) from ' +
@@ -529,7 +529,7 @@ describe('traverseAllChildren', function() {
// serialization (timezones) so let's test a regex instead:
expect(function() {
traverseAllChildren(/abc/, function() {}, null);
}).toThrow(
}).toThrowError(
'Objects are not valid as a React child (found: /abc/). If you meant ' +
'to render a collection of children, use an array instead or wrap the ' +
'object using createFragment(object) from the React add-ons.'
-128
View File
@@ -1,128 +0,0 @@
/**
* 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.
*
* @providesModule MetaMatchers
*/
'use strict';
/**
* This modules adds a jasmine matcher toEqualSpecsIn that can be used to
* compare the specs in two different "describe" functions and their result.
* It can be used to test a test.
*/
function getRunnerWithResults(describeFunction) {
if (describeFunction._cachedRunner) {
// Cached result of execution. This is a convenience way to test against
// the same authoritative function multiple times.
return describeFunction._cachedRunner;
}
// Patch the current global environment.
var env = new jasmine.Env();
// Execute the tests synchronously.
env.updateInterval = 0;
var outerGetEnv = jasmine.getEnv;
jasmine.getEnv = function() {
return env;
};
// TODO: Bring over matchers from the existing environment.
var runner = env.currentRunner();
try {
env.describe('', describeFunction);
env.execute();
} finally {
// Restore the environment.
jasmine.getEnv = outerGetEnv;
}
describeFunction._cachedRunner = runner;
return runner;
}
function compareSpec(actual, expected) {
if (actual.results().totalCount !== expected.results().totalCount) {
return (
'Expected ' + expected.results().totalCount + ' expects, ' +
'but got ' + actual.results().totalCount + ':' +
actual.getFullName()
);
}
return null;
}
function includesDescription(specs, description, startIndex) {
for (var i = startIndex; i < specs.length; i++) {
if (specs[i].description === description) {
return true;
}
}
return false;
}
function compareSpecs(actualSpecs, expectedSpecs) {
for (var i = 0; i < actualSpecs.length && i < expectedSpecs.length; i++) {
var actual = actualSpecs[i];
var expected = expectedSpecs[i];
if (actual.description === expected.description) {
var errorMessage = compareSpec(actual, expected);
if (errorMessage) {
return errorMessage;
}
continue;
} else if (includesDescription(actualSpecs, expected.description, i)) {
return 'Did not expect the spec:' + actualSpecs[i].getFullName();
} else {
return 'Expected an equivalent to:' + expectedSpecs[i].getFullName();
}
}
if (i < actualSpecs.length) {
return 'Did not expect the spec:' + actualSpecs[i].getFullName();
}
if (i < expectedSpecs.length) {
return 'Expected an equivalent to:' + expectedSpecs[i].getFullName();
}
return null;
}
function compareDescription(a, b) {
if (a.description === b.description) {
return 0;
}
return a.description < b.description ? -1 : 1;
}
function compareRunners(actual, expected) {
return compareSpecs(
actual.specs().sort(compareDescription),
expected.specs().sort(compareDescription)
);
}
var MetaMatchers = {
toEqualSpecsIn: function(expectedDescribeFunction) {
var actualDescribeFunction = this.actual;
if (typeof actualDescribeFunction !== 'function') {
throw Error('toEqualSpecsIn() should be used on a describe function');
}
if (typeof expectedDescribeFunction !== 'function') {
throw Error('toEqualSpecsIn() should be passed a describe function');
}
var actual = getRunnerWithResults(actualDescribeFunction);
var expected = getRunnerWithResults(expectedDescribeFunction);
var errorMessage = compareRunners(actual, expected);
this.message = function() {
return [
errorMessage,
'The specs are equal. Expected them to be different.',
];
};
return !errorMessage;
},
};
module.exports = MetaMatchers;
-62
View File
@@ -1,62 +0,0 @@
/**
* 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.
*
* @emails react-core
*/
'use strict';
var MetaMatchers = require('MetaMatchers');
describe('meta-matchers', function() {
beforeEach(function() {
this.addMatchers(MetaMatchers);
});
function a() {
it('should add 1 and 2', function() {
expect(1 + 2).toBe(3);
});
}
function b() {
it('should add 1 and 2', function() {
expect(1 + 2).toBe(3);
});
}
function c() {
it('should add 1 and 2', function() {
expect(1 + 2).toBe(3);
});
it('should mutiply 1 and 2', function() {
expect(1 * 2).toBe(2);
});
}
function d() {
it('should add 1 and 2', function() {
expect(1 + 2).toBe(3);
});
it('should mutiply 1 and 2', function() {
expect(1 * 2).toBe(2);
expect(2 * 1).toBe(2);
});
}
it('tests equality of specs', function() {
expect(a).toEqualSpecsIn(b);
});
it('tests inequality of specs and expects', function() {
expect(b).not.toEqualSpecsIn(c);
expect(c).not.toEqualSpecsIn(d);
});
});
+8 -8
View File
@@ -75,12 +75,12 @@ describe('ReactTestUtils', function() {
});
var shallowRenderer = ReactTestUtils.createRenderer();
expect(() => shallowRenderer.render(SomeComponent)).toThrow(
expect(() => shallowRenderer.render(SomeComponent)).toThrowError(
'ReactShallowRenderer render(): Invalid component element. Instead of ' +
'passing a component class, make sure to instantiate it by passing it ' +
'to React.createElement.'
);
expect(() => shallowRenderer.render(<div />)).toThrow(
expect(() => shallowRenderer.render(<div />)).toThrowError(
'ReactShallowRenderer render(): Shallow rendering works only with ' +
'custom components, not primitives (div). Instead of calling ' +
'`.render(el)` and inspecting the rendered output, look at `el.props` ' +
@@ -288,9 +288,9 @@ describe('ReactTestUtils', function() {
var shallowRenderer = ReactTestUtils.createRenderer();
shallowRenderer.render(<SimpleComponent />);
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 context type: Required context `name` was not ' +
'specified in `SimpleComponent`.\n' +
@@ -458,7 +458,7 @@ describe('ReactTestUtils', function() {
e.persist();
},
};
spyOn(obj, 'handler').andCallThrough();
spyOn(obj, 'handler').and.callThrough();
var container = document.createElement('div');
var instance = ReactDOM.render(<input type="text" onChange={obj.handler} />, container);
@@ -485,7 +485,7 @@ describe('ReactTestUtils', function() {
e.persist();
},
};
spyOn(obj, 'handler').andCallThrough();
spyOn(obj, 'handler').and.callThrough();
var container = document.createElement('div');
var instance = ReactDOM.render(<SomeComponent handleChange={obj.handler} />, container);
@@ -510,7 +510,7 @@ describe('ReactTestUtils', function() {
var shallowRenderer = ReactTestUtils.createRenderer();
var result = shallowRenderer.render(<SomeComponent handleClick={handler} />);
expect(() => ReactTestUtils.Simulate.click(result)).toThrow(
expect(() => ReactTestUtils.Simulate.click(result)).toThrowError(
'TestUtils.Simulate expects a component instance and not a ReactElement.' +
'TestUtils.Simulate will not work if you are using shallow rendering.'
);
@@ -537,7 +537,7 @@ describe('ReactTestUtils', function() {
ReactDOM.findDOMNode(instance),
{clientX: CLIENT_X}
);
expect(console.error.calls.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
});
it('can scry with stateless components involved', function() {