mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Upgrade to jest-cli@0.9 and use Jasmine2
This commit is contained in:
committed by
Dan Abramov
parent
510155e027
commit
d8a0b9a662
@@ -99,6 +99,7 @@
|
||||
"<rootDir>/src",
|
||||
"node_modules/fbjs"
|
||||
],
|
||||
"testRunner": "node_modules/jest-cli/src/testRunners/jasmine/jasmine2.js",
|
||||
"unmockedModulePathPatterns": [
|
||||
""
|
||||
]
|
||||
|
||||
Vendored
+1
@@ -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
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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');
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.'
|
||||
);
|
||||
});
|
||||
@@ -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 ' +
|
||||
@@ -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);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -51,8 +51,8 @@ describe 'ReactCoffeeScriptClass', ->
|
||||
expect(->
|
||||
ReactDOM.render React.createElement(Foo), container
|
||||
).toThrow()
|
||||
expect(console.error.calls.length).toBe(1)
|
||||
expect(console.error.argsForCall[0][0]).toContain('No `render` method found on the returned component instance')
|
||||
expect(console.error.calls.count()).toBe(1)
|
||||
expect(console.error.calls.argsFor(0)[0]).toContain('No `render` method found on the returned component instance')
|
||||
|
||||
it 'renders a simple stateless component with prop', ->
|
||||
class Foo extends React.Component
|
||||
@@ -153,7 +153,7 @@ describe 'ReactCoffeeScriptClass', ->
|
||||
|
||||
expect(->
|
||||
test React.createElement(Foo), 'span', ''
|
||||
).toThrow(
|
||||
).toThrowError(
|
||||
'Foo.state: must be set to an object or null'
|
||||
)
|
||||
|
||||
@@ -292,17 +292,17 @@ describe 'ReactCoffeeScriptClass', ->
|
||||
test React.createElement(Foo), 'SPAN', 'foo'
|
||||
expect(getInitialStateWasCalled).toBe false
|
||||
expect(getDefaultPropsWasCalled).toBe false
|
||||
expect(console.error.calls.length).toBe 4
|
||||
expect(console.error.argsForCall[0][0]).toContain(
|
||||
expect(console.error.calls.count()).toBe 4
|
||||
expect(console.error.calls.argsFor(0)[0]).toContain(
|
||||
'getInitialState was defined on Foo, a plain JavaScript class.'
|
||||
)
|
||||
expect(console.error.argsForCall[1][0]).toContain(
|
||||
expect(console.error.calls.argsFor(1)[0]).toContain(
|
||||
'getDefaultProps was defined on Foo, a plain JavaScript class.'
|
||||
)
|
||||
expect(console.error.argsForCall[2][0]).toContain(
|
||||
expect(console.error.calls.argsFor(2)[0]).toContain(
|
||||
'propTypes was defined as an instance property on Foo.'
|
||||
)
|
||||
expect(console.error.argsForCall[3][0]).toContain(
|
||||
expect(console.error.calls.argsFor(3)[0]).toContain(
|
||||
'contextTypes was defined as an instance property on Foo.'
|
||||
)
|
||||
|
||||
@@ -317,8 +317,8 @@ describe 'ReactCoffeeScriptClass', ->
|
||||
className: 'foo'
|
||||
|
||||
test React.createElement(NamedComponent), 'SPAN', 'foo'
|
||||
expect(console.error.calls.length).toBe 1
|
||||
expect(console.error.argsForCall[0][0]).toBe(
|
||||
expect(console.error.calls.count()).toBe 1
|
||||
expect(console.error.calls.argsFor(0)[0]).toBe(
|
||||
'Warning: NamedComponent has a method called componentShouldUpdate().
|
||||
Did you mean shouldComponentUpdate()? The name is phrased as a
|
||||
question because the function is expected to return a value.'
|
||||
@@ -335,8 +335,8 @@ describe 'ReactCoffeeScriptClass', ->
|
||||
className: 'foo'
|
||||
|
||||
test React.createElement(NamedComponent), 'SPAN', 'foo'
|
||||
expect(console.error.calls.length).toBe 1
|
||||
expect(console.error.argsForCall[0][0]).toBe(
|
||||
expect(console.error.calls.count()).toBe 1
|
||||
expect(console.error.calls.argsFor(0)[0]).toBe(
|
||||
'Warning: NamedComponent has a method called componentWillRecieveProps().
|
||||
Did you mean componentWillReceiveProps()?'
|
||||
)
|
||||
@@ -349,11 +349,11 @@ describe 'ReactCoffeeScriptClass', ->
|
||||
expect(-> instance.isMounted()).toThrow()
|
||||
expect(-> instance.setProps name: 'bar').toThrow()
|
||||
expect(-> instance.replaceProps name: 'bar').toThrow()
|
||||
expect(console.error.calls.length).toBe 2
|
||||
expect(console.error.argsForCall[0][0]).toContain(
|
||||
expect(console.error.calls.count()).toBe 2
|
||||
expect(console.error.calls.argsFor(0)[0]).toContain(
|
||||
'replaceState(...) is deprecated in plain JavaScript React classes'
|
||||
)
|
||||
expect(console.error.argsForCall[1][0]).toContain(
|
||||
expect(console.error.calls.argsFor(1)[0]).toContain(
|
||||
'isMounted(...) is deprecated in plain JavaScript React classes'
|
||||
)
|
||||
|
||||
|
||||
@@ -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'
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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: 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: client text</div>\n' +
|
||||
' (server) nbsp entity: 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.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.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.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.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.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.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);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -329,29 +329,29 @@ describe('ReactDOMInput', function() {
|
||||
it('should warn with value and no onChange handler', function() {
|
||||
var link = new ReactLink('yolo', jest.fn());
|
||||
ReactTestUtils.renderIntoDocument(<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() {
|
||||
@@ -407,8 +407,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.'
|
||||
);
|
||||
|
||||
@@ -419,27 +419,27 @@ describe('ReactDOMInput', function() {
|
||||
onChange={jest.fn()}
|
||||
/>
|
||||
);
|
||||
expect(console.error.argsForCall.length).toBe(1);
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
|
||||
ReactTestUtils.renderIntoDocument(
|
||||
<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() {
|
||||
@@ -488,21 +488,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 ' +
|
||||
@@ -514,14 +514,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 ' +
|
||||
@@ -533,7 +533,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() {
|
||||
@@ -541,8 +541,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 ' +
|
||||
@@ -555,8 +555,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 ' +
|
||||
@@ -569,8 +569,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 ' +
|
||||
@@ -583,8 +583,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 ' +
|
||||
@@ -597,8 +597,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 ' +
|
||||
@@ -611,8 +611,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 ' +
|
||||
@@ -625,8 +625,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 ' +
|
||||
@@ -639,8 +639,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 ' +
|
||||
@@ -653,8 +653,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 ' +
|
||||
@@ -668,7 +668,7 @@ describe('ReactDOMInput', function() {
|
||||
}
|
||||
var log = [];
|
||||
var originalCreateElement = document.createElement;
|
||||
spyOn(document, 'createElement').andCallFake(function(type) {
|
||||
spyOn(document, 'createElement').and.callFake(function(type) {
|
||||
var el = originalCreateElement.apply(this, arguments);
|
||||
if (type === 'input') {
|
||||
Object.defineProperty(el, 'value', {
|
||||
@@ -677,7 +677,7 @@ describe('ReactDOMInput', function() {
|
||||
log.push('set value');
|
||||
},
|
||||
});
|
||||
spyOn(el, 'setAttribute').andCallFake(function(name, value) {
|
||||
spyOn(el, 'setAttribute').and.callFake(function(name, value) {
|
||||
log.push('set ' + name);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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:');
|
||||
|
||||
@@ -128,8 +128,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: ' +
|
||||
@@ -142,22 +142,22 @@ describe('ReactDOMComponent', function() {
|
||||
style.background = 'green';
|
||||
stub.setState({style: {background: 'green'}});
|
||||
// already warned once for the same component and owner
|
||||
expect(console.error.argsForCall.length).toBe(1);
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
|
||||
style = {background: 'red'};
|
||||
var div = document.createElement('div');
|
||||
ReactDOM.render(<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 **)'
|
||||
);
|
||||
@@ -180,8 +180,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.'
|
||||
@@ -189,12 +189,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.'
|
||||
@@ -202,7 +202,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() {
|
||||
@@ -213,8 +213,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.',
|
||||
);
|
||||
});
|
||||
@@ -352,8 +352,8 @@ describe('ReactDOMComponent', function() {
|
||||
);
|
||||
ReactDOM.render(element, container);
|
||||
}
|
||||
expect(console.error.argsForCall.length).toBe(1);
|
||||
expect(console.error.argsForCall[0][0]).toEqual(
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).toEqual(
|
||||
'Warning: Invalid attribute name: `blah" onclick="beevil" noise="hi`'
|
||||
);
|
||||
});
|
||||
@@ -372,8 +372,8 @@ describe('ReactDOMComponent', function() {
|
||||
);
|
||||
ReactDOM.render(afterUpdate, container);
|
||||
}
|
||||
expect(console.error.argsForCall.length).toBe(1);
|
||||
expect(console.error.argsForCall[0][0]).toEqual(
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).toEqual(
|
||||
'Warning: Invalid attribute name: `blah" onclick="beevil" noise="hi`'
|
||||
);
|
||||
});
|
||||
@@ -654,27 +654,34 @@ describe('ReactDOMComponent', function() {
|
||||
);
|
||||
};
|
||||
|
||||
this.addMatchers({
|
||||
toHaveAttribute: function(attr, value) {
|
||||
var expected = '(?:^|\\s)' + attr + '=[\\\'"]';
|
||||
if (typeof value !== 'undefined') {
|
||||
expected += quoteRegexp(value) + '[\\\'"]';
|
||||
}
|
||||
return this.actual.match(new RegExp(expected));
|
||||
jasmine.addMatchers({
|
||||
toHaveAttribute() {
|
||||
return {
|
||||
compare(actual, expected) {
|
||||
var [attr, value] = expected;
|
||||
var re = '(?:^|\\s)' + attr + '=[\\\'"]';
|
||||
if (typeof value !== 'undefined') {
|
||||
re += quoteRegexp(value) + '[\\\'"]';
|
||||
}
|
||||
return {
|
||||
pass: (new RegExp(re)).test(actual),
|
||||
};
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should generate the correct markup with className', function() {
|
||||
expect(genMarkup({className: 'a'})).toHaveAttribute('class', 'a');
|
||||
expect(genMarkup({className: 'a b'})).toHaveAttribute('class', 'a b');
|
||||
expect(genMarkup({className: ''})).toHaveAttribute('class', '');
|
||||
expect(genMarkup({className: 'a'})).toHaveAttribute(['class', 'a']);
|
||||
expect(genMarkup({className: 'a b'})).toHaveAttribute(['class', 'a b']);
|
||||
expect(genMarkup({className: ''})).toHaveAttribute(['class', '']);
|
||||
});
|
||||
|
||||
it('should escape style names and values', function() {
|
||||
expect(genMarkup({
|
||||
style: {'b&ckground': '<3'},
|
||||
})).toHaveAttribute('style', 'b&ckground:<3;');
|
||||
})).toHaveAttribute(['style', 'b&ckground:<3;']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -704,10 +711,16 @@ describe('ReactDOMComponent', function() {
|
||||
);
|
||||
};
|
||||
|
||||
this.addMatchers({
|
||||
toHaveInnerhtml: function(html) {
|
||||
var expected = '^' + quoteRegexp(html) + '$';
|
||||
return this.actual.match(new RegExp(expected));
|
||||
jasmine.addMatchers({
|
||||
toHaveInnerhtml() {
|
||||
return {
|
||||
compare(actual, expected) {
|
||||
var re = '^' + quoteRegexp(expected) + '$';
|
||||
return {
|
||||
pass: (new RegExp(re)).test(actual),
|
||||
};
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -745,7 +758,7 @@ describe('ReactDOMComponent', function() {
|
||||
|
||||
expect(function() {
|
||||
ReactDOM.render(<input>children</input>, container);
|
||||
}).toThrow(
|
||||
}).toThrowError(
|
||||
'input is a void element tag and must not have `children` or ' +
|
||||
'use `props.dangerouslySetInnerHTML`.'
|
||||
);
|
||||
@@ -759,7 +772,7 @@ describe('ReactDOMComponent', function() {
|
||||
<input dangerouslySetInnerHTML={{__html: 'content'}} />,
|
||||
container
|
||||
);
|
||||
}).toThrow(
|
||||
}).toThrowError(
|
||||
'input is a void element tag and must not have `children` or use ' +
|
||||
'`props.dangerouslySetInnerHTML`.'
|
||||
);
|
||||
@@ -774,7 +787,7 @@ describe('ReactDOMComponent', function() {
|
||||
|
||||
expect(function() {
|
||||
ReactDOM.render(<menu><menuitem>children</menuitem></menu>, container);
|
||||
}).toThrow(
|
||||
}).toThrowError(
|
||||
'menuitem is a void element tag and must not have `children` or use ' +
|
||||
'`props.dangerouslySetInnerHTML`.'
|
||||
);
|
||||
@@ -784,7 +797,7 @@ describe('ReactDOMComponent', function() {
|
||||
it('should validate against multiple children props', function() {
|
||||
expect(function() {
|
||||
mountComponent({children: '', dangerouslySetInnerHTML: ''});
|
||||
}).toThrow(
|
||||
}).toThrowError(
|
||||
'Can only set one of `children` or `props.dangerouslySetInnerHTML`.'
|
||||
);
|
||||
});
|
||||
@@ -793,8 +806,8 @@ describe('ReactDOMComponent', function() {
|
||||
|
||||
spyOn(console, 'error');
|
||||
mountComponent({innerHTML: '<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. '
|
||||
);
|
||||
});
|
||||
@@ -802,7 +815,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.'
|
||||
);
|
||||
@@ -811,7 +824,7 @@ describe('ReactDOMComponent', function() {
|
||||
it('should validate use of dangerouslySetInnerHTML', function() {
|
||||
expect(function() {
|
||||
mountComponent({dangerouslySetInnerHTML: {foo: 'bar'} });
|
||||
}).toThrow(
|
||||
}).toThrowError(
|
||||
'`props.dangerouslySetInnerHTML` must be in the form `{__html: ...}`. ' +
|
||||
'Please visit https://fb.me/react-invariant-dangerously-set-inner-html for more information.'
|
||||
);
|
||||
@@ -826,20 +839,20 @@ describe('ReactDOMComponent', function() {
|
||||
it('should warn about contentEditable and children', function() {
|
||||
spyOn(console, 'error');
|
||||
mountComponent({contentEditable: true, children: ''});
|
||||
expect(console.error.argsForCall.length).toBe(1);
|
||||
expect(console.error.argsForCall[0][0]).toContain('contentEditable');
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).toContain('contentEditable');
|
||||
});
|
||||
|
||||
it('should respect suppressContentEditableWarning', function() {
|
||||
spyOn(console, 'error');
|
||||
mountComponent({contentEditable: true, children: '', suppressContentEditableWarning: true});
|
||||
expect(console.error.argsForCall.length).toBe(0);
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('should validate against invalid styles', function() {
|
||||
expect(function() {
|
||||
mountComponent({style: 'display: none'});
|
||||
}).toThrow(
|
||||
}).toThrowError(
|
||||
'The `style` prop expects a mapping from style properties to values, ' +
|
||||
'not a string. For example, style={{marginRight: spacing + \'em\'}} ' +
|
||||
'when using JSX.'
|
||||
@@ -929,7 +942,7 @@ describe('ReactDOMComponent', function() {
|
||||
var container = document.createElement('div');
|
||||
expect(function() {
|
||||
ReactDOM.render(<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.'
|
||||
);
|
||||
@@ -959,7 +972,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`.'
|
||||
);
|
||||
@@ -973,7 +986,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`.'
|
||||
);
|
||||
@@ -987,7 +1000,7 @@ describe('ReactDOMComponent', function() {
|
||||
<div children="" dangerouslySetInnerHTML={{__html: ''}}></div>,
|
||||
container
|
||||
);
|
||||
}).toThrow(
|
||||
}).toThrowError(
|
||||
'Can only set one of `children` or `props.dangerouslySetInnerHTML`.'
|
||||
);
|
||||
});
|
||||
@@ -998,8 +1011,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() {
|
||||
@@ -1007,7 +1020,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.'
|
||||
@@ -1023,7 +1036,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`.'
|
||||
@@ -1128,8 +1141,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'
|
||||
);
|
||||
});
|
||||
@@ -1147,7 +1160,7 @@ describe('ReactDOMComponent', function() {
|
||||
var hackzor = React.createElement('script tag');
|
||||
expect(
|
||||
() => ReactTestUtils.renderIntoDocument(hackzor)
|
||||
).toThrow(
|
||||
).toThrowError(
|
||||
'Invalid tag: script tag'
|
||||
);
|
||||
});
|
||||
@@ -1157,7 +1170,7 @@ describe('ReactDOMComponent', function() {
|
||||
var hackzor = React.createElement('div><img /><div');
|
||||
expect(
|
||||
() => ReactTestUtils.renderIntoDocument(hackzor)
|
||||
).toThrow(
|
||||
).toThrowError(
|
||||
'Invalid tag: div><img /><div'
|
||||
);
|
||||
});
|
||||
@@ -1174,8 +1187,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.'
|
||||
);
|
||||
@@ -1186,8 +1199,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.'
|
||||
);
|
||||
@@ -1207,13 +1220,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.'
|
||||
);
|
||||
@@ -1245,8 +1258,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.'
|
||||
);
|
||||
|
||||
@@ -1257,26 +1270,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.'
|
||||
);
|
||||
|
||||
@@ -1286,8 +1299,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.'
|
||||
);
|
||||
});
|
||||
@@ -1295,66 +1308,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(0)).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(0)).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 **)'
|
||||
@@ -1366,12 +1379,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 **)'
|
||||
);
|
||||
@@ -1391,14 +1404,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,
|
||||
@@ -1442,14 +1455,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,
|
||||
|
||||
@@ -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`.'
|
||||
);
|
||||
|
||||
@@ -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 ' +
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.ForCall(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.ForCall(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.'
|
||||
|
||||
+24
-17
@@ -32,6 +32,7 @@ function getRunnerWithResults(describeFunction) {
|
||||
return env;
|
||||
};
|
||||
// TODO: Bring over matchers from the existing environment.
|
||||
console.error(env);
|
||||
var runner = env.currentRunner();
|
||||
try {
|
||||
env.describe('', describeFunction);
|
||||
@@ -104,24 +105,30 @@ function compareRunners(actual, expected) {
|
||||
}
|
||||
|
||||
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.',
|
||||
];
|
||||
toEqualSpecsIn(/* util, customEqualityMatcher*/) {
|
||||
return {
|
||||
compare(actualDescribeFunction, expectedDescribeFunction) {
|
||||
if (typeof actualDescribeFunction !== 'function') {
|
||||
throw Error('toEqualSpecsIn() should be used on a describe function');
|
||||
}
|
||||
if (typeof expectedDescribeFunction !== 'function') {
|
||||
throw Error('toEqualSpecsIn() should be passed a describe function');
|
||||
}
|
||||
var actual = getRunnerWithResults(actualDescribeFunction);
|
||||
var expected = getRunnerWithResults(expectedDescribeFunction);
|
||||
var errorMessage = compareRunners(actual, expected);
|
||||
|
||||
return {
|
||||
passed: !errorMessage,
|
||||
message: function() {
|
||||
return [
|
||||
errorMessage,
|
||||
'The specs are equal. Expected them to be different.',
|
||||
];
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
return !errorMessage;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ var MetaMatchers = require('MetaMatchers');
|
||||
describe('meta-matchers', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
this.addMatchers(MetaMatchers);
|
||||
jasmine.addMatchers(MetaMatchers);
|
||||
});
|
||||
|
||||
function a() {
|
||||
|
||||
@@ -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` ' +
|
||||
@@ -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.'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user