@@ -302,11 +339,15 @@ describe('ReactChildren', () => {
assertCalls();
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
- 'Warning: Each child in an array or iterator should have a unique "key" prop.'
+ 'Warning: Each child in an array or iterator should have a unique "key" prop.',
);
console.error.calls.reset();
- var mappedChildren = React.Children.map(instance.props.children, callback, context);
+ var mappedChildren = React.Children.map(
+ instance.props.children,
+ callback,
+ context,
+ );
assertCalls();
expectDev(console.error.calls.count()).toBe(0);
expect(mappedChildren).toEqual([
@@ -333,11 +374,10 @@ describe('ReactChildren', () => {
};
var context = {};
- var callback =
- jasmine.createSpy().and.callFake(function(kid) {
- expect(this).toBe(context);
- return kid;
- });
+ var callback = jasmine.createSpy().and.callFake(function(kid) {
+ expect(this).toBe(context);
+ return kid;
+ });
var instance = (
@@ -356,7 +396,11 @@ describe('ReactChildren', () => {
React.Children.forEach(instance.props.children, callback, context);
assertCalls();
- var mappedChildren = React.Children.map(instance.props.children, callback, context);
+ var mappedChildren = React.Children.map(
+ instance.props.children,
+ callback,
+ context,
+ );
assertCalls();
expect(mappedChildren).toEqual([
,
@@ -398,7 +442,11 @@ describe('ReactChildren', () => {
React.Children.forEach(instance.props.children, callback, context);
assertCalls();
- var mappedChildren = React.Children.map(instance.props.children, callback, context);
+ var mappedChildren = React.Children.map(
+ instance.props.children,
+ callback,
+ context,
+ );
assertCalls();
expect(mappedChildren).toEqual([5, 12, 13]);
} finally {
@@ -435,12 +483,13 @@ describe('ReactChildren', () => {
React.Children.forEach(instance.props.children, callback, context);
assertCalls();
- var mappedChildren = React.Children.map(instance.props.children, callback, context);
+ var mappedChildren = React.Children.map(
+ instance.props.children,
+ callback,
+ context,
+ );
assertCalls();
- expect(mappedChildren).toEqual([
- 'a',
- 13,
- ]);
+ expect(mappedChildren).toEqual(['a', 13]);
delete String.prototype.key;
delete Number.prototype.key;
@@ -477,8 +526,11 @@ describe('ReactChildren', () => {
React.Children.forEach(instance.props.children, callback, scopeTester);
expect(lastContext).toBe(scopeTester);
- var mappedChildren =
- React.Children.map(instance.props.children, callback, scopeTester);
+ var mappedChildren = React.Children.map(
+ instance.props.children,
+ callback,
+ scopeTester,
+ );
expect(React.Children.count(mappedChildren)).toBe(1);
expect(mappedChildren[0]).toBe(scopeTester);
@@ -492,9 +544,9 @@ describe('ReactChildren', () => {
var four =
;
var mapped = [
-
, // Key should be joined to obj key
- null, // Key should be added even if we don't supply it!
-
, // Key should be added even if not supplied!
+
, // Key should be joined to obj key
+ null, // Key should be added even if we don't supply it!
+
, // Key should be added even if not supplied!
, // Map from null to something.
,
];
@@ -520,8 +572,7 @@ describe('ReactChildren', () => {
expect(callback).toHaveBeenCalledWith(four, 4);
callback.calls.reset();
- var mappedChildren =
- React.Children.map(instance.props.children, callback);
+ var mappedChildren = React.Children.map(instance.props.children, callback);
expect(callback.calls.count()).toBe(5);
expect(React.Children.count(mappedChildren)).toBe(4);
// Keys default to indices.
@@ -530,9 +581,7 @@ describe('ReactChildren', () => {
mappedChildren[1].key,
mappedChildren[2].key,
mappedChildren[3].key,
- ]).toEqual(
- ['giraffe/.$keyZero', '.$keyTwo', '.3', '.$keyFour']
- );
+ ]).toEqual(['giraffe/.$keyZero', '.$keyTwo', '.3', '.$keyFour']);
expect(callback).toHaveBeenCalledWith(zero, 0);
expect(callback).toHaveBeenCalledWith(one, 1);
@@ -559,15 +608,15 @@ describe('ReactChildren', () => {
// 1. If grouped in an Object, the object key combined with `key` prop
// 2. If grouped in an Array, the `key` prop, falling back to array index
- var zeroMapped =
; // Key should be overridden
- var twoMapped =
; // Key should be added even if not supplied!
+ var zeroMapped =
; // Key should be overridden
+ var twoMapped =
; // Key should be added even if not supplied!
var fourMapped =
;
var fiveMapped =
;
var callback = jasmine.createSpy().and.callFake(function(kid, index) {
- return index === 0 ? zeroMapped :
- index === 1 ? twoMapped :
- index === 2 ? fourMapped : fiveMapped;
+ return index === 0
+ ? zeroMapped
+ : index === 1 ? twoMapped : index === 2 ? fourMapped : fiveMapped;
});
var frag = ReactFragment.create({
@@ -577,12 +626,7 @@ describe('ReactChildren', () => {
});
var instance =
{[frag]}
;
- expect([
- frag[0].key,
- frag[1].key,
- frag[2].key,
- frag[3].key,
- ]).toEqual([
+ expect([frag[0].key, frag[1].key, frag[2].key, frag[3].key]).toEqual([
'firstHalfKey/.$keyZero',
'firstHalfKey/.$keyTwo',
'secondHalfKey/.$keyFour',
@@ -618,9 +662,13 @@ describe('ReactChildren', () => {
'.0:$keyFive/.$keyFiveInner',
]);
- expect(mappedChildren[0]).toEqual(
);
+ expect(mappedChildren[0]).toEqual(
+
,
+ );
expect(mappedChildren[1]).toEqual(
);
- expect(mappedChildren[2]).toEqual(
);
+ expect(mappedChildren[2]).toEqual(
+
,
+ );
expect(mappedChildren[3]).toEqual(
);
});
@@ -645,21 +693,24 @@ describe('ReactChildren', () => {
);
var expectedForcedKeys = ['giraffe/.$keyZero', '.$keyOne'];
- var mappedChildrenForcedKeys =
- React.Children.map(forcedKeys.props.children, mapFn);
- var mappedForcedKeys = mappedChildrenForcedKeys.map((c) => c.key);
+ var mappedChildrenForcedKeys = React.Children.map(
+ forcedKeys.props.children,
+ mapFn,
+ );
+ var mappedForcedKeys = mappedChildrenForcedKeys.map(c => c.key);
expect(mappedForcedKeys).toEqual(expectedForcedKeys);
var expectedRemappedForcedKeys = [
'giraffe/.$giraffe/.$keyZero',
'.$.$keyOne',
];
- var remappedChildrenForcedKeys =
- React.Children.map(mappedChildrenForcedKeys, mapFn);
- expect(
- remappedChildrenForcedKeys.map((c) => c.key)
- ).toEqual(expectedRemappedForcedKeys);
-
+ var remappedChildrenForcedKeys = React.Children.map(
+ mappedChildrenForcedKeys,
+ mapFn,
+ );
+ expect(remappedChildrenForcedKeys.map(c => c.key)).toEqual(
+ expectedRemappedForcedKeys,
+ );
});
it('should not throw if key provided is a dupe with array key', () => {
@@ -694,10 +745,8 @@ describe('ReactChildren', () => {
element => element,
);
- var mappedWithClone = React.Children.map(
- instance.props.children,
- element => React.cloneElement(element),
- );
+ var mappedWithClone = React.Children.map(instance.props.children, element =>
+ React.cloneElement(element));
expect(mapped[0].key).toBe(mappedWithClone[0].key);
});
@@ -714,10 +763,8 @@ describe('ReactChildren', () => {
element => element,
);
- var mappedWithClone = React.Children.map(
- instance.props.children,
- element => React.cloneElement(element, {key: 'unique'}),
- );
+ var mappedWithClone = React.Children.map(instance.props.children, element =>
+ React.cloneElement(element, {key: 'unique'}));
expect(mapped[0].key).toBe(mappedWithClone[0].key);
});
@@ -773,14 +820,16 @@ describe('ReactChildren', () => {
// 2. If grouped in an Array, the `key` prop, falling back to array index
var instance = (
-
{[
- ReactFragment.create({
- firstHalfKey: [zero, one, two],
- secondHalfKey: [three, four],
- keyFive: five,
- }),
- null,
- ]}
+
+ {[
+ ReactFragment.create({
+ firstHalfKey: [zero, one, two],
+ secondHalfKey: [three, four],
+ keyFive: five,
+ }),
+ null,
+ ]}
+
);
var numberOfChildren = React.Children.count(instance.props.children);
expect(numberOfChildren).toBe(5);
@@ -792,10 +841,8 @@ describe('ReactChildren', () => {
expect(React.Children.toArray(
).length).toBe(1);
expect(React.Children.toArray([
]).length).toBe(1);
- expect(
- React.Children.toArray(
)[0].key
- ).toBe(
- React.Children.toArray([
])[0].key
+ expect(React.Children.toArray(
)[0].key).toBe(
+ React.Children.toArray([
])[0].key,
);
var flattened = React.Children.toArray([
@@ -819,9 +866,10 @@ describe('ReactChildren', () => {
expect(flattened[5].key).toBe(reversed[3].key);
// null/undefined/bool are all omitted
- expect(React.Children.toArray([1, 'two', null, undefined, true])).toEqual(
- [1, 'two']
- );
+ expect(React.Children.toArray([1, 'two', null, undefined, true])).toEqual([
+ 1,
+ 'two',
+ ]);
});
it('should throw on object', () => {
@@ -829,9 +877,9 @@ describe('ReactChildren', () => {
React.Children.forEach({a: 1, b: 2}, function() {}, null);
}).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 ' +
- 'the React add-ons.'
+ '{a, b}). 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.',
);
});
@@ -842,8 +890,8 @@ describe('ReactChildren', () => {
React.Children.forEach(/abc/, function() {}, null);
}).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.'
+ 'to render a collection of children, use an array instead or wrap the ' +
+ 'object using createFragment(object) from the React add-ons.',
);
});
});
diff --git a/src/isomorphic/children/__tests__/onlyChild-test.js b/src/isomorphic/children/__tests__/onlyChild-test.js
index 3481fbccac..45ee0f74b3 100644
--- a/src/isomorphic/children/__tests__/onlyChild-test.js
+++ b/src/isomorphic/children/__tests__/onlyChild-test.js
@@ -12,7 +12,6 @@
'use strict';
describe('onlyChild', () => {
-
var React;
var ReactFragment;
var onlyChild;
@@ -35,60 +34,64 @@ describe('onlyChild', () => {
it('should fail when passed two children', () => {
expect(function() {
- var instance =
+ var instance = (
- ;
+
+ );
onlyChild(instance.props.children);
}).toThrow();
});
it('should fail when passed nully values', () => {
expect(function() {
- var instance =
+ var instance = (
{null}
- ;
+
+ );
onlyChild(instance.props.children);
}).toThrow();
expect(function() {
- var instance =
+ var instance = (
{undefined}
- ;
+
+ );
onlyChild(instance.props.children);
}).toThrow();
});
it('should fail when key/value objects', () => {
expect(function() {
- var instance =
+ var instance = (
{ReactFragment.create({oneThing: })}
- ;
+
+ );
onlyChild(instance.props.children);
}).toThrow();
});
-
it('should not fail when passed interpolated single child', () => {
expect(function() {
- var instance =
+ var instance = (
{}
- ;
+
+ );
onlyChild(instance.props.children);
}).not.toThrow();
});
it('should return the only child', () => {
- var instance =
+ var instance = (
- ;
+
+ );
expect(onlyChild(instance.props.children)).toEqual(
);
});
-
});
diff --git a/src/isomorphic/children/onlyChild.js b/src/isomorphic/children/onlyChild.js
index c273cb592c..efe815594c 100644
--- a/src/isomorphic/children/onlyChild.js
+++ b/src/isomorphic/children/onlyChild.js
@@ -31,7 +31,7 @@ var invariant = require('fbjs/lib/invariant');
function onlyChild(children) {
invariant(
ReactElement.isValidElement(children),
- 'React.Children.only expected to receive a single React element child.'
+ 'React.Children.only expected to receive a single React element child.',
);
return children;
}
diff --git a/src/isomorphic/classic/__tests__/ReactContextValidator-test.js b/src/isomorphic/classic/__tests__/ReactContextValidator-test.js
index d1ddfc665a..dfd0f21809 100644
--- a/src/isomorphic/classic/__tests__/ReactContextValidator-test.js
+++ b/src/isomorphic/classic/__tests__/ReactContextValidator-test.js
@@ -66,7 +66,9 @@ describe('ReactContextValidator', () => {
},
});
- var instance = ReactTestUtils.renderIntoDocument(
);
+ var instance = ReactTestUtils.renderIntoDocument(
+
,
+ );
expect(instance.refs.child.context).toEqual({foo: 'abc'});
});
@@ -184,9 +186,9 @@ describe('ReactContextValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Failed context type: ' +
- 'The context `foo` is marked as required in `Component`, but its value ' +
- 'is `undefined`.\n' +
- ' in Component (at **)'
+ 'The context `foo` is marked as required in `Component`, but its value ' +
+ 'is `undefined`.\n' +
+ ' in Component (at **)',
);
var ComponentInFooStringContext = React.createClass({
@@ -206,7 +208,7 @@ describe('ReactContextValidator', () => {
});
ReactTestUtils.renderIntoDocument(
-
+
,
);
// Previous call should not error
@@ -228,15 +230,17 @@ describe('ReactContextValidator', () => {
},
});
- ReactTestUtils.renderIntoDocument(
);
+ ReactTestUtils.renderIntoDocument(
+
,
+ );
expectDev(console.error.calls.count()).toBe(2);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
'Warning: Failed context type: ' +
- 'Invalid context `foo` of type `number` supplied ' +
- 'to `Component`, expected `string`.\n' +
- ' in Component (at **)\n' +
- ' in ComponentInFooNumberContext (at **)'
+ 'Invalid context `foo` of type `number` supplied ' +
+ 'to `Component`, expected `string`.\n' +
+ ' in Component (at **)\n' +
+ ' in ComponentInFooNumberContext (at **)',
);
});
@@ -262,9 +266,9 @@ describe('ReactContextValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Failed child context type: ' +
- 'The child context `foo` is marked as required in `Component`, but its ' +
- 'value is `undefined`.\n' +
- ' in Component (at **)'
+ 'The child context `foo` is marked as required in `Component`, but its ' +
+ 'value is `undefined`.\n' +
+ ' in Component (at **)',
);
ReactTestUtils.renderIntoDocument(
);
@@ -272,18 +276,16 @@ describe('ReactContextValidator', () => {
expectDev(console.error.calls.count()).toBe(2);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
'Warning: Failed child context type: ' +
- 'Invalid child context `foo` of type `number` ' +
- 'supplied to `Component`, expected `string`.\n' +
- ' in Component (at **)'
+ 'Invalid child context `foo` of type `number` ' +
+ 'supplied to `Component`, expected `string`.\n' +
+ ' in Component (at **)',
);
ReactTestUtils.renderIntoDocument(
-
+
,
);
- ReactTestUtils.renderIntoDocument(
-
- );
+ ReactTestUtils.renderIntoDocument(
);
// Previous calls should not log errors
expectDev(console.error.calls.count()).toBe(2);
@@ -315,8 +317,8 @@ describe('ReactContextValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: ComponentA.childContextTypes is specified but there is no ' +
- 'getChildContext() method on the instance. You can either define ' +
- 'getChildContext() on ComponentA or remove childContextTypes from it.'
+ 'getChildContext() method on the instance. You can either define ' +
+ 'getChildContext() on ComponentA or remove childContextTypes from it.',
);
// Warnings should be deduped by component type
@@ -326,8 +328,8 @@ describe('ReactContextValidator', () => {
expectDev(console.error.calls.count()).toBe(2);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
'Warning: ComponentB.childContextTypes is specified but there is no ' +
- 'getChildContext() method on the instance. You can either define ' +
- 'getChildContext() on ComponentB or remove childContextTypes from it.'
+ 'getChildContext() method on the instance. You can either define ' +
+ 'getChildContext() on ComponentB or remove childContextTypes from it.',
);
});
@@ -375,5 +377,4 @@ describe('ReactContextValidator', () => {
expect(childContext.bar).toBeUndefined();
expect(childContext.foo).toBe('FOO');
});
-
});
diff --git a/src/isomorphic/classic/class/ReactClass.js b/src/isomorphic/classic/class/ReactClass.js
index ee85b4aefc..fb1c07ec08 100644
--- a/src/isomorphic/classic/class/ReactClass.js
+++ b/src/isomorphic/classic/class/ReactClass.js
@@ -36,23 +36,19 @@ type SpecPolicy =
/**
* These methods may be defined only once by the class specification or mixin.
*/
- 'DEFINE_ONCE' |
- /**
+ | 'DEFINE_ONCE' /**
* These methods may be defined by both the class specification and mixins.
* Subsequent definitions will be chained. These methods must return void.
*/
- 'DEFINE_MANY' |
- /**
+ | 'DEFINE_MANY' /**
* These methods are overriding the base class.
*/
- 'OVERRIDE_BASE' |
- /**
+ | 'OVERRIDE_BASE' /**
* These methods are similar to DEFINE_MANY, except we assume they return
* objects. We try to merge the keys of the return values of all the mixed in
* functions. If there is a key conflict we throw.
*/
- 'DEFINE_MANY_MERGED';
-
+ | 'DEFINE_MANY_MERGED';
/**
* Composite components are higher-level components that compose other composite
@@ -77,7 +73,6 @@ type SpecPolicy =
* @internal
*/
var ReactClassInterface: {[key: string]: SpecPolicy} = {
-
/**
* An array of Mixin objects to include when defining your component.
*
@@ -172,8 +167,6 @@ var ReactClassInterface: {[key: string]: SpecPolicy} = {
*/
render: 'DEFINE_ONCE',
-
-
// ==== Delegate methods ====
/**
@@ -284,8 +277,6 @@ var ReactClassInterface: {[key: string]: SpecPolicy} = {
*/
componentWillUnmount: 'DEFINE_MANY',
-
-
// ==== Advanced methods ====
/**
@@ -299,7 +290,6 @@ var ReactClassInterface: {[key: string]: SpecPolicy} = {
* @overridable
*/
updateComponent: 'OVERRIDE_BASE',
-
};
/**
@@ -324,30 +314,22 @@ var RESERVED_SPEC_KEYS = {
},
childContextTypes: function(Constructor, childContextTypes) {
if (__DEV__) {
- validateTypeDef(
- Constructor,
- childContextTypes,
- 'child context'
- );
+ validateTypeDef(Constructor, childContextTypes, 'child context');
}
Constructor.childContextTypes = Object.assign(
{},
Constructor.childContextTypes,
- childContextTypes
+ childContextTypes,
);
},
contextTypes: function(Constructor, contextTypes) {
if (__DEV__) {
- validateTypeDef(
- Constructor,
- contextTypes,
- 'context'
- );
+ validateTypeDef(Constructor, contextTypes, 'context');
}
Constructor.contextTypes = Object.assign(
{},
Constructor.contextTypes,
- contextTypes
+ contextTypes,
);
},
/**
@@ -358,7 +340,7 @@ var RESERVED_SPEC_KEYS = {
if (Constructor.getDefaultProps) {
Constructor.getDefaultProps = createMergedResultFunction(
Constructor.getDefaultProps,
- getDefaultProps
+ getDefaultProps,
);
} else {
Constructor.getDefaultProps = getDefaultProps;
@@ -366,17 +348,9 @@ var RESERVED_SPEC_KEYS = {
},
propTypes: function(Constructor, propTypes) {
if (__DEV__) {
- validateTypeDef(
- Constructor,
- propTypes,
- 'prop'
- );
+ validateTypeDef(Constructor, propTypes, 'prop');
}
- Constructor.propTypes = Object.assign(
- {},
- Constructor.propTypes,
- propTypes
- );
+ Constructor.propTypes = Object.assign({}, Constructor.propTypes, propTypes);
},
statics: function(Constructor, statics) {
mixStaticSpecIntoComponent(Constructor, statics);
@@ -384,11 +358,7 @@ var RESERVED_SPEC_KEYS = {
autobind: function() {}, // noop
};
-function validateTypeDef(
- Constructor,
- typeDef,
- location: string,
-) {
+function validateTypeDef(Constructor, typeDef, location: string) {
for (var propName in typeDef) {
if (typeDef.hasOwnProperty(propName)) {
// use a warning instead of an invariant so components
@@ -396,40 +366,39 @@ function validateTypeDef(
warning(
typeof typeDef[propName] === 'function',
'%s: %s type `%s` is invalid; it must be a function, usually from ' +
- 'React.PropTypes.',
+ 'React.PropTypes.',
Constructor.displayName || 'ReactClass',
location,
- propName
+ propName,
);
}
}
}
function validateMethodOverride(isAlreadyDefined, name) {
- var specPolicy = ReactClassInterface.hasOwnProperty(name) ?
- ReactClassInterface[name] :
- null;
+ var specPolicy = ReactClassInterface.hasOwnProperty(name)
+ ? ReactClassInterface[name]
+ : null;
// Disallow overriding of base class methods unless explicitly allowed.
if (ReactClassMixin.hasOwnProperty(name)) {
invariant(
specPolicy === 'OVERRIDE_BASE',
'ReactClassInterface: You are attempting to override ' +
- '`%s` from your class specification. Ensure that your method names ' +
- 'do not overlap with React methods.',
- name
+ '`%s` from your class specification. Ensure that your method names ' +
+ 'do not overlap with React methods.',
+ name,
);
}
// Disallow defining methods more than once unless explicitly allowed.
if (isAlreadyDefined) {
invariant(
- specPolicy === 'DEFINE_MANY' ||
- specPolicy === 'DEFINE_MANY_MERGED',
+ specPolicy === 'DEFINE_MANY' || specPolicy === 'DEFINE_MANY_MERGED',
'ReactClassInterface: You are attempting to define ' +
- '`%s` on your component more than once. This conflict may be due ' +
- 'to a mixin.',
- name
+ '`%s` on your component more than once. This conflict may be due ' +
+ 'to a mixin.',
+ name,
);
}
}
@@ -446,12 +415,12 @@ function mixSpecIntoComponent(Constructor, spec) {
warning(
isMixinValid,
- '%s: You\'re attempting to include a mixin that is either null ' +
- 'or not an object. Check the mixins included by the component, ' +
- 'as well as any mixins they include themselves. ' +
- 'Expected object but got %s.',
+ "%s: You're attempting to include a mixin that is either null " +
+ 'or not an object. Check the mixins included by the component, ' +
+ 'as well as any mixins they include themselves. ' +
+ 'Expected object but got %s.',
Constructor.displayName || 'ReactClass',
- spec === null ? null : typeofSpec
+ spec === null ? null : typeofSpec,
);
}
@@ -460,14 +429,14 @@ function mixSpecIntoComponent(Constructor, spec) {
invariant(
typeof spec !== 'function',
- 'ReactClass: You\'re attempting to ' +
- 'use a component class or function as a mixin. Instead, just use a ' +
- 'regular object.'
+ "ReactClass: You're attempting to " +
+ 'use a component class or function as a mixin. Instead, just use a ' +
+ 'regular object.',
);
invariant(
!ReactElement.isValidElement(spec),
- 'ReactClass: You\'re attempting to ' +
- 'use a component as a mixin. Instead, just use a regular object.'
+ "ReactClass: You're attempting to " +
+ 'use a component as a mixin. Instead, just use a regular object.',
);
var proto = Constructor.prototype;
@@ -501,11 +470,9 @@ function mixSpecIntoComponent(Constructor, spec) {
// The following member methods should not be automatically bound:
// 1. Expected ReactClass methods (in the "interface").
// 2. Overridden methods (that were mixed in).
- var isReactClassMethod =
- ReactClassInterface.hasOwnProperty(name);
+ var isReactClassMethod = ReactClassInterface.hasOwnProperty(name);
var isFunction = typeof property === 'function';
- var shouldAutoBind =
- isFunction &&
+ var shouldAutoBind = isFunction &&
!isReactClassMethod &&
!isAlreadyDefined &&
spec.autobind !== false;
@@ -519,14 +486,13 @@ function mixSpecIntoComponent(Constructor, spec) {
// These cases should already be caught by validateMethodOverride.
invariant(
- isReactClassMethod && (
- specPolicy === 'DEFINE_MANY_MERGED' ||
- specPolicy === 'DEFINE_MANY'
- ),
+ isReactClassMethod &&
+ (specPolicy === 'DEFINE_MANY_MERGED' ||
+ specPolicy === 'DEFINE_MANY'),
'ReactClass: Unexpected spec policy %s for key %s ' +
- 'when mixing in component specs.',
+ 'when mixing in component specs.',
specPolicy,
- name
+ name,
);
// For methods which are defined more than once, call the existing
@@ -565,19 +531,19 @@ function mixStaticSpecIntoComponent(Constructor, statics) {
invariant(
!isReserved,
'ReactClass: You are attempting to define a reserved ' +
- 'property, `%s`, that shouldn\'t be on the "statics" key. Define it ' +
- 'as an instance property instead; it will still be accessible on the ' +
- 'constructor.',
- name
+ 'property, `%s`, that shouldn\'t be on the "statics" key. Define it ' +
+ 'as an instance property instead; it will still be accessible on the ' +
+ 'constructor.',
+ name,
);
var isInherited = name in Constructor;
invariant(
!isInherited,
'ReactClass: You are attempting to define ' +
- '`%s` on your component more than once. This conflict may be ' +
- 'due to a mixin.',
- name
+ '`%s` on your component more than once. This conflict may be ' +
+ 'due to a mixin.',
+ name,
);
Constructor[name] = property;
}
@@ -593,7 +559,7 @@ function mixStaticSpecIntoComponent(Constructor, statics) {
function mergeIntoWithNoDuplicateKeys(one, two) {
invariant(
one && two && typeof one === 'object' && typeof two === 'object',
- 'mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.'
+ 'mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.',
);
for (var key in two) {
@@ -601,11 +567,11 @@ function mergeIntoWithNoDuplicateKeys(one, two) {
invariant(
one[key] === undefined,
'mergeIntoWithNoDuplicateKeys(): ' +
- 'Tried to merge two objects with the same key: `%s`. This conflict ' +
- 'may be due to a mixin; in particular, this may be caused by two ' +
- 'getInitialState() or getDefaultProps() methods returning objects ' +
- 'with clashing keys.',
- key
+ 'Tried to merge two objects with the same key: `%s`. This conflict ' +
+ 'may be due to a mixin; in particular, this may be caused by two ' +
+ 'getInitialState() or getDefaultProps() methods returning objects ' +
+ 'with clashing keys.',
+ key,
);
one[key] = two[key];
}
@@ -675,16 +641,16 @@ function bindAutoBindMethod(component, method) {
warning(
false,
'bind(): React component methods may only be bound to the ' +
- 'component instance.\n\nSee %s',
- componentName
+ 'component instance.\n\nSee %s',
+ componentName,
);
} else if (!args.length) {
warning(
false,
'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.\n\nSee %s',
- componentName
+ 'React does this for you automatically in a high-performance ' +
+ 'way, so you can safely remove this call.\n\nSee %s',
+ componentName,
);
return boundMethod;
}
@@ -708,10 +674,7 @@ function bindAutoBindMethods(component) {
for (var i = 0; i < pairs.length; i += 2) {
var autoBindKey = pairs[i];
var method = pairs[i + 1];
- component[autoBindKey] = bindAutoBindMethod(
- component,
- method
- );
+ component[autoBindKey] = bindAutoBindMethod(component, method);
}
}
@@ -720,7 +683,6 @@ function bindAutoBindMethods(component) {
* therefore not already part of the modern ReactComponent.
*/
var ReactClassMixin = {
-
/**
* TODO: This will be deprecated because state should always keep a consistent
* type signature and the only use case for this, is to avoid that.
@@ -744,7 +706,7 @@ var ReactClassComponent = function() {};
Object.assign(
ReactClassComponent.prototype,
ReactComponent.prototype,
- ReactClassMixin
+ ReactClassMixin,
);
/**
@@ -753,7 +715,6 @@ Object.assign(
* @class ReactClass
*/
var ReactClass = {
-
/**
* Creates a composite component class given a class specification.
* See https://facebook.github.io/react/docs/react-api.html#createclass
@@ -774,7 +735,7 @@ var ReactClass = {
warning(
this instanceof Constructor,
'Something is calling a React component directly. Use a factory or ' +
- 'JSX instead. See: https://fb.me/react-legacyfactory'
+ 'JSX instead. See: https://fb.me/react-legacyfactory',
);
}
@@ -796,8 +757,9 @@ var ReactClass = {
var initialState = this.getInitialState ? this.getInitialState() : null;
if (__DEV__) {
// We allow auto-mocks to proceed as if they're returning null.
- if (initialState === undefined &&
- this.getInitialState._isMockFunction) {
+ if (
+ initialState === undefined && this.getInitialState._isMockFunction
+ ) {
// This is probably bad practice. Consider warning here and
// deprecating this convenience.
initialState = null;
@@ -806,7 +768,7 @@ var ReactClass = {
invariant(
typeof initialState === 'object' && !Array.isArray(initialState),
'%s.getInitialState(): must return an object or null',
- Constructor.displayName || 'ReactCompositeComponent'
+ Constructor.displayName || 'ReactCompositeComponent',
);
this.state = initialState;
@@ -837,23 +799,23 @@ var ReactClass = {
invariant(
Constructor.prototype.render,
- 'createClass(...): Class specification must implement a `render` method.'
+ 'createClass(...): Class specification must implement a `render` method.',
);
if (__DEV__) {
warning(
!Constructor.prototype.componentShouldUpdate,
'%s 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.',
- spec.displayName || 'A component'
+ 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
+ 'The name is phrased as a question because the function is ' +
+ 'expected to return a value.',
+ spec.displayName || 'A component',
);
warning(
!Constructor.prototype.componentWillRecieveProps,
'%s has a method called ' +
- 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?',
- spec.displayName || 'A component'
+ 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?',
+ spec.displayName || 'A component',
);
}
@@ -866,7 +828,6 @@ var ReactClass = {
return Constructor;
},
-
};
module.exports = ReactClass;
diff --git a/src/isomorphic/classic/class/__tests__/ReactBind-test.js b/src/isomorphic/classic/class/__tests__/ReactBind-test.js
index bab8bba87d..051db5a8fe 100644
--- a/src/isomorphic/classic/class/__tests__/ReactBind-test.js
+++ b/src/isomorphic/classic/class/__tests__/ReactBind-test.js
@@ -16,9 +16,7 @@ var ReactTestUtils = require('ReactTestUtils');
// TODO: Test render and all stock methods.
describe('autobinding', () => {
-
it('Holds reference to instance', () => {
-
var mouseDidEnter = jest.fn();
var mouseDidLeave = jest.fn();
var mouseDidClick = jest.fn();
@@ -115,7 +113,7 @@ describe('autobinding', () => {
spyOn(console, 'error');
var TestBindComponent = React.createClass({
- handleClick: function() { },
+ handleClick: function() {},
render: function() {
return
;
},
@@ -126,8 +124,8 @@ describe('autobinding', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(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.\n\nSee TestBindComponent'
+ 'React does this for you automatically in a high-performance ' +
+ 'way, so you can safely remove this call.\n\nSee TestBindComponent',
);
});
@@ -141,9 +139,7 @@ describe('autobinding', () => {
componentDidMount: function() {
this.setState({foo: 2}, this.handleUpdate);
},
- handleUpdate: function() {
-
- },
+ handleUpdate: function() {},
render: function() {
return
;
},
@@ -153,5 +149,4 @@ describe('autobinding', () => {
expectDev(console.error.calls.count()).toBe(0);
});
-
});
diff --git a/src/isomorphic/classic/class/__tests__/ReactBindOptout-test.js b/src/isomorphic/classic/class/__tests__/ReactBindOptout-test.js
index 69abd3904f..086329338f 100644
--- a/src/isomorphic/classic/class/__tests__/ReactBindOptout-test.js
+++ b/src/isomorphic/classic/class/__tests__/ReactBindOptout-test.js
@@ -16,9 +16,7 @@ var ReactTestUtils = require('ReactTestUtils');
// TODO: Test render and all stock methods.
describe('autobind optout', () => {
-
it('should work with manual binding', () => {
-
var mouseDidEnter = jest.fn();
var mouseDidLeave = jest.fn();
var mouseDidClick = jest.fn();
@@ -39,7 +37,7 @@ describe('autobind optout', () => {
onMouseOver={this.onMouseEnter.bind(this)}
onMouseOut={this.onMouseLeave.bind(this)}
onClick={this.onClick.bind(this)}
- />
+ />
);
},
});
@@ -95,12 +93,7 @@ describe('autobind optout', () => {
},
render: function() {
- return (
-
- );
+ return
;
},
});
@@ -178,7 +171,7 @@ describe('autobind optout', () => {
var TestBindComponent = React.createClass({
autobind: false,
- handleClick: function() { },
+ handleClick: function() {},
render: function() {
return
;
},
@@ -200,9 +193,7 @@ describe('autobind optout', () => {
componentDidMount: function() {
this.setState({foo: 2}, this.handleUpdate.bind(this));
},
- handleUpdate: function() {
-
- },
+ handleUpdate: function() {},
render: function() {
return
;
},
@@ -212,5 +203,4 @@ describe('autobind optout', () => {
expectDev(console.error.calls.count()).toBe(0);
});
-
});
diff --git a/src/isomorphic/classic/class/__tests__/ReactClass-test.js b/src/isomorphic/classic/class/__tests__/ReactClass-test.js
index b727f7ba3b..4ab5ad7dac 100644
--- a/src/isomorphic/classic/class/__tests__/ReactClass-test.js
+++ b/src/isomorphic/classic/class/__tests__/ReactClass-test.js
@@ -16,7 +16,6 @@ var ReactDOM;
var ReactTestUtils;
describe('ReactClass-spec', () => {
-
beforeEach(() => {
React = require('react');
ReactDOM = require('react-dom');
@@ -27,7 +26,7 @@ describe('ReactClass-spec', () => {
expect(function() {
React.createClass({});
}).toThrowError(
- 'createClass(...): Class specification must implement a `render` method.'
+ 'createClass(...): Class specification must implement a `render` method.',
);
});
@@ -38,8 +37,7 @@ describe('ReactClass-spec', () => {
},
});
- expect(TestComponent.displayName)
- .toBe('TestComponent');
+ expect(TestComponent.displayName).toBe('TestComponent');
});
it('should copy prop types onto the Constructor', () => {
@@ -54,8 +52,7 @@ describe('ReactClass-spec', () => {
});
expect(TestComponent.propTypes).toBeDefined();
- expect(TestComponent.propTypes.value)
- .toBe(propValidator);
+ expect(TestComponent.propTypes.value).toBe(propValidator);
});
it('should warn on invalid prop types', () => {
@@ -72,7 +69,7 @@ describe('ReactClass-spec', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Component: prop type `prop` is invalid; ' +
- 'it must be a function, usually from React.PropTypes.'
+ 'it must be a function, usually from React.PropTypes.',
);
});
@@ -90,7 +87,7 @@ describe('ReactClass-spec', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Component: context type `prop` is invalid; ' +
- 'it must be a function, usually from React.PropTypes.'
+ 'it must be a function, usually from React.PropTypes.',
);
});
@@ -108,7 +105,7 @@ describe('ReactClass-spec', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Component: child context type `prop` is invalid; ' +
- 'it must be a function, usually from React.PropTypes.'
+ 'it must be a function, usually from React.PropTypes.',
);
});
@@ -126,8 +123,8 @@ describe('ReactClass-spec', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(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.'
+ 'mean shouldComponentUpdate()? The name is phrased as a question ' +
+ 'because the function is expected to return a value.',
);
React.createClass({
@@ -142,8 +139,8 @@ describe('ReactClass-spec', () => {
expectDev(console.error.calls.count()).toBe(2);
expectDev(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.'
+ 'mean shouldComponentUpdate()? The name is phrased as a question ' +
+ 'because the function is expected to return a value.',
);
});
@@ -160,7 +157,7 @@ describe('ReactClass-spec', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: A component has a method called componentWillRecieveProps(). Did you ' +
- 'mean componentWillReceiveProps()?'
+ 'mean componentWillReceiveProps()?',
);
});
@@ -181,9 +178,9 @@ describe('ReactClass-spec', () => {
});
}).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 ' +
- 'the constructor.'
+ '`getDefaultProps`, that shouldn\'t be on the "statics" key. Define ' +
+ 'it as an instance property instead; it will still be accessible on ' +
+ 'the constructor.',
);
});
@@ -209,19 +206,19 @@ describe('ReactClass-spec', () => {
expectDev(console.error.calls.count()).toBe(4);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'createClass(...): `mixins` is now a static property and should ' +
- 'be defined inside "statics".'
+ 'be defined inside "statics".',
);
expectDev(console.error.calls.argsFor(1)[0]).toBe(
'createClass(...): `propTypes` is now a static property and should ' +
- 'be defined inside "statics".'
+ 'be defined inside "statics".',
);
expectDev(console.error.calls.argsFor(2)[0]).toBe(
'createClass(...): `contextTypes` is now a static property and ' +
- 'should be defined inside "statics".'
+ 'should be defined inside "statics".',
);
expectDev(console.error.calls.argsFor(3)[0]).toBe(
'createClass(...): `childContextTypes` is now a static property and ' +
- 'should be defined inside "statics".'
+ 'should be defined inside "statics".',
);
});
@@ -315,7 +312,7 @@ describe('ReactClass-spec', () => {
expect(function() {
instance = ReactTestUtils.renderIntoDocument(instance);
}).toThrowError(
- 'Component.getInitialState(): must return an object or null'
+ 'Component.getInitialState(): must return an object or null',
);
});
});
@@ -329,9 +326,8 @@ describe('ReactClass-spec', () => {
return
;
},
});
- expect(
- () => ReactTestUtils.renderIntoDocument(
)
- ).not.toThrow();
+ expect(() =>
+ ReactTestUtils.renderIntoDocument(
)).not.toThrow();
});
it('should throw when using legacy factories', () => {
@@ -346,8 +342,7 @@ describe('ReactClass-spec', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(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'
+ 'factory or JSX instead. See: https://fb.me/react-legacyfactory',
);
});
-
});
diff --git a/src/isomorphic/classic/class/__tests__/ReactClassMixin-test.js b/src/isomorphic/classic/class/__tests__/ReactClassMixin-test.js
index 992bc55578..2f079a69fc 100644
--- a/src/isomorphic/classic/class/__tests__/ReactClassMixin-test.js
+++ b/src/isomorphic/classic/class/__tests__/ReactClassMixin-test.js
@@ -21,7 +21,6 @@ var mixinPropValidator;
var componentPropValidator;
describe('ReactClass-mixin', () => {
-
beforeEach(() => {
React = require('react');
ReactTestUtils = require('ReactTestUtils');
@@ -149,23 +148,22 @@ describe('ReactClass-mixin', () => {
it('should validate prop types via mixins', () => {
expect(TestComponent.propTypes).toBeDefined();
- expect(TestComponent.propTypes.value)
- .toBe(mixinPropValidator);
+ expect(TestComponent.propTypes.value).toBe(mixinPropValidator);
});
it('should override mixin prop types with class prop types', () => {
// Sanity check...
expect(componentPropValidator).not.toBe(mixinPropValidator);
// Actually check...
- expect(TestComponentWithPropTypes.propTypes)
- .toBeDefined();
- expect(TestComponentWithPropTypes.propTypes.value)
- .not.toBe(mixinPropValidator);
- expect(TestComponentWithPropTypes.propTypes.value)
- .toBe(componentPropValidator);
+ expect(TestComponentWithPropTypes.propTypes).toBeDefined();
+ expect(TestComponentWithPropTypes.propTypes.value).not.toBe(
+ mixinPropValidator,
+ );
+ expect(TestComponentWithPropTypes.propTypes.value).toBe(
+ componentPropValidator,
+ );
});
-
it('should support mixins with getInitialState()', () => {
var Mixin = {
getInitialState: function() {
@@ -205,9 +203,9 @@ describe('ReactClass-mixin', () => {
ReactTestUtils.renderIntoDocument(
);
}).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() ' +
- 'methods returning objects with clashing keys.'
+ 'same key: `x`. This conflict may be due to a mixin; in particular, ' +
+ 'this may be caused by two getInitialState() or getDefaultProps() ' +
+ 'methods returning objects with clashing keys.',
);
});
@@ -276,7 +274,7 @@ describe('ReactClass-mixin', () => {
});
}).toThrowError(
'ReactClass: You are attempting to define `abc` on your component more ' +
- 'than once. This conflict may be due to a mixin.'
+ 'than once. This conflict may be due to a mixin.',
);
});
@@ -304,7 +302,7 @@ describe('ReactClass-mixin', () => {
});
}).toThrowError(
'ReactClass: You are attempting to define `abc` on your component ' +
- 'more than once. This conflict may be due to a mixin.'
+ 'more than once. This conflict may be due to a mixin.',
);
});
@@ -321,10 +319,10 @@ describe('ReactClass-mixin', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
- 'Warning: ReactClass: You\'re attempting to include a mixin that is ' +
- 'either null or not an object. Check the mixins included by the ' +
- 'component, as well as any mixins they include themselves. ' +
- 'Expected object but got undefined.'
+ "Warning: ReactClass: You're attempting to include a mixin that is " +
+ 'either null or not an object. Check the mixins included by the ' +
+ 'component, as well as any mixins they include themselves. ' +
+ 'Expected object but got undefined.',
);
});
@@ -341,10 +339,10 @@ describe('ReactClass-mixin', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
- 'Warning: ReactClass: You\'re attempting to include a mixin that is ' +
- 'either null or not an object. Check the mixins included by the ' +
- 'component, as well as any mixins they include themselves. ' +
- 'Expected object but got null.'
+ "Warning: ReactClass: You're attempting to include a mixin that is " +
+ 'either null or not an object. Check the mixins included by the ' +
+ 'component, as well as any mixins they include themselves. ' +
+ 'Expected object but got null.',
);
});
@@ -365,10 +363,10 @@ describe('ReactClass-mixin', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
- 'Warning: ReactClass: You\'re attempting to include a mixin that is ' +
- 'either null or not an object. Check the mixins included by the ' +
- 'component, as well as any mixins they include themselves. ' +
- 'Expected object but got undefined.'
+ "Warning: ReactClass: You're attempting to include a mixin that is " +
+ 'either null or not an object. Check the mixins included by the ' +
+ 'component, as well as any mixins they include themselves. ' +
+ 'Expected object but got undefined.',
);
});
@@ -389,10 +387,10 @@ describe('ReactClass-mixin', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
- 'Warning: ReactClass: You\'re attempting to include a mixin that is ' +
- 'either null or not an object. Check the mixins included by the ' +
- 'component, as well as any mixins they include themselves. ' +
- 'Expected object but got null.'
+ "Warning: ReactClass: You're attempting to include a mixin that is " +
+ 'either null or not an object. Check the mixins included by the ' +
+ 'component, as well as any mixins they include themselves. ' +
+ 'Expected object but got null.',
);
});
@@ -406,8 +404,8 @@ describe('ReactClass-mixin', () => {
},
});
}).toThrowError(
- 'ReactClass: You\'re attempting to use a component as a mixin. ' +
- 'Instead, just use a regular object.'
+ "ReactClass: You're attempting to use a component as a mixin. " +
+ 'Instead, just use a regular object.',
);
});
@@ -427,8 +425,8 @@ describe('ReactClass-mixin', () => {
},
});
}).toThrowError(
- 'ReactClass: You\'re attempting to use a component class or function ' +
- 'as a mixin. Instead, just use a regular object.'
+ "ReactClass: You're attempting to use a component class or function " +
+ 'as a mixin. Instead, just use a regular object.',
);
});
@@ -488,9 +486,8 @@ describe('ReactClass-mixin', () => {
return
;
},
});
- expect(
- () => ReactTestUtils.renderIntoDocument(
)
- ).not.toThrow();
+ expect(() =>
+ ReactTestUtils.renderIntoDocument(
)).not.toThrow();
instance = ReactTestUtils.renderIntoDocument(
);
expect(instance.state).toEqual({foo: 'bar'});
@@ -510,9 +507,8 @@ describe('ReactClass-mixin', () => {
return
;
},
});
- expect(
- () => ReactTestUtils.renderIntoDocument(
)
- ).not.toThrow();
+ expect(() =>
+ ReactTestUtils.renderIntoDocument(
)).not.toThrow();
instance = ReactTestUtils.renderIntoDocument(
);
expect(instance.state).toEqual({foo: 'bar'});
@@ -527,12 +523,10 @@ describe('ReactClass-mixin', () => {
return
;
},
});
- expect(
- () => ReactTestUtils.renderIntoDocument(
)
- ).not.toThrow();
+ expect(() =>
+ ReactTestUtils.renderIntoDocument(
)).not.toThrow();
instance = ReactTestUtils.renderIntoDocument(
);
expect(instance.state).toEqual({foo: 'bar', x: true});
});
-
});
diff --git a/src/isomorphic/classic/element/ReactCurrentOwner.js b/src/isomorphic/classic/element/ReactCurrentOwner.js
index e9a6ea5b5c..3a12b523bd 100644
--- a/src/isomorphic/classic/element/ReactCurrentOwner.js
+++ b/src/isomorphic/classic/element/ReactCurrentOwner.js
@@ -12,8 +12,8 @@
'use strict';
-import type { ReactInstance } from 'ReactInstanceType';
-import type { Fiber } from 'ReactFiber';
+import type {ReactInstance} from 'ReactInstanceType';
+import type {Fiber} from 'ReactFiber';
/**
* Keeps track of the current owner.
@@ -22,13 +22,11 @@ import type { Fiber } from 'ReactFiber';
* currently being constructed.
*/
var ReactCurrentOwner = {
-
/**
* @internal
* @type {ReactComponent}
*/
current: (null: null | ReactInstance | Fiber),
-
};
module.exports = ReactCurrentOwner;
diff --git a/src/isomorphic/classic/element/ReactDOMFactories.js b/src/isomorphic/classic/element/ReactDOMFactories.js
index 4890fa676c..c6ee9fc5d1 100644
--- a/src/isomorphic/classic/element/ReactDOMFactories.js
+++ b/src/isomorphic/classic/element/ReactDOMFactories.js
@@ -141,7 +141,7 @@ var ReactDOMFactories = {
track: createDOMFactory('track'),
u: createDOMFactory('u'),
ul: createDOMFactory('ul'),
- 'var': createDOMFactory('var'),
+ var: createDOMFactory('var'),
video: createDOMFactory('video'),
wbr: createDOMFactory('wbr'),
diff --git a/src/isomorphic/classic/element/ReactDebugCurrentFrame.js b/src/isomorphic/classic/element/ReactDebugCurrentFrame.js
index ee8ab2248e..38dcf3c73d 100644
--- a/src/isomorphic/classic/element/ReactDebugCurrentFrame.js
+++ b/src/isomorphic/classic/element/ReactDebugCurrentFrame.js
@@ -12,8 +12,8 @@
'use strict';
-import type { Fiber } from 'ReactFiber';
-import type { DebugID } from 'ReactInstanceType';
+import type {Fiber} from 'ReactFiber';
+import type {DebugID} from 'ReactInstanceType';
const ReactDebugCurrentFrame = {};
@@ -27,12 +27,12 @@ if (__DEV__) {
} = require('ReactFiberComponentTreeHook');
// Component that is being worked on
- ReactDebugCurrentFrame.current = (null : Fiber | DebugID | null);
+ ReactDebugCurrentFrame.current = (null: Fiber | DebugID | null);
// Element that is being cloned or created
- ReactDebugCurrentFrame.element = (null : *);
+ ReactDebugCurrentFrame.element = (null: *);
- ReactDebugCurrentFrame.getStackAddendum = function() : string | null {
+ ReactDebugCurrentFrame.getStackAddendum = function(): string | null {
let stack = null;
const current = ReactDebugCurrentFrame.current;
const element = ReactDebugCurrentFrame.element;
diff --git a/src/isomorphic/classic/element/ReactElement.js b/src/isomorphic/classic/element/ReactElement.js
index 7db7d5949a..b47d5e247f 100644
--- a/src/isomorphic/classic/element/ReactElement.js
+++ b/src/isomorphic/classic/element/ReactElement.js
@@ -59,10 +59,10 @@ function defineKeyPropWarningGetter(props, displayName) {
warning(
false,
'%s: `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 ' +
- 'prop. (https://fb.me/react-special-props)',
- displayName
+ 'in `undefined` being returned. If you need to access the same ' +
+ 'value within the child component, you should pass it as a different ' +
+ 'prop. (https://fb.me/react-special-props)',
+ displayName,
);
}
};
@@ -80,10 +80,10 @@ function defineRefPropWarningGetter(props, displayName) {
warning(
false,
'%s: `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 ' +
- 'prop. (https://fb.me/react-special-props)',
- displayName
+ 'in `undefined` being returned. If you need to access the same ' +
+ 'value within the child component, you should pass it as a different ' +
+ 'prop. (https://fb.me/react-special-props)',
+ displayName,
);
}
};
@@ -203,8 +203,10 @@ ReactElement.createElement = function(type, config, children) {
source = config.__source === undefined ? null : config.__source;
// Remaining properties are added to a new props object
for (propName in config) {
- if (hasOwnProperty.call(config, propName) &&
- !RESERVED_PROPS.hasOwnProperty(propName)) {
+ if (
+ hasOwnProperty.call(config, propName) &&
+ !RESERVED_PROPS.hasOwnProperty(propName)
+ ) {
props[propName] = config[propName];
}
}
@@ -239,11 +241,13 @@ ReactElement.createElement = function(type, config, children) {
}
if (__DEV__) {
if (key || ref) {
- if (typeof props.$$typeof === 'undefined' ||
- props.$$typeof !== REACT_ELEMENT_TYPE) {
- var displayName = typeof type === 'function' ?
- (type.displayName || type.name || 'Unknown') :
- type;
+ if (
+ typeof props.$$typeof === 'undefined' ||
+ props.$$typeof !== REACT_ELEMENT_TYPE
+ ) {
+ var displayName = typeof type === 'function'
+ ? type.displayName || type.name || 'Unknown'
+ : type;
if (key) {
defineKeyPropWarningGetter(props, displayName);
}
@@ -260,7 +264,7 @@ ReactElement.createElement = function(type, config, children) {
self,
source,
ReactCurrentOwner.current,
- props
+ props,
);
};
@@ -287,7 +291,7 @@ ReactElement.cloneAndReplaceKey = function(oldElement, newKey) {
oldElement._self,
oldElement._source,
oldElement._owner,
- oldElement.props
+ oldElement.props,
);
return newElement;
@@ -332,8 +336,10 @@ ReactElement.cloneElement = function(element, config, children) {
defaultProps = element.type.defaultProps;
}
for (propName in config) {
- if (hasOwnProperty.call(config, propName) &&
- !RESERVED_PROPS.hasOwnProperty(propName)) {
+ if (
+ hasOwnProperty.call(config, propName) &&
+ !RESERVED_PROPS.hasOwnProperty(propName)
+ ) {
if (config[propName] === undefined && defaultProps !== undefined) {
// Resolve default props
props[propName] = defaultProps[propName];
@@ -357,15 +363,7 @@ ReactElement.cloneElement = function(element, config, children) {
props.children = childArray;
}
- return ReactElement(
- element.type,
- key,
- ref,
- self,
- source,
- owner,
- props
- );
+ return ReactElement(element.type, key, ref, self, source, owner, props);
};
/**
@@ -376,11 +374,9 @@ ReactElement.cloneElement = function(element, config, children) {
* @final
*/
ReactElement.isValidElement = function(object) {
- return (
- typeof object === 'object' &&
+ return typeof object === 'object' &&
object !== null &&
- object.$$typeof === REACT_ELEMENT_TYPE
- );
+ object.$$typeof === REACT_ELEMENT_TYPE;
};
module.exports = ReactElement;
diff --git a/src/isomorphic/classic/element/ReactElementValidator.js b/src/isomorphic/classic/element/ReactElementValidator.js
index f2a699dc9e..dbe09c8154 100644
--- a/src/isomorphic/classic/element/ReactElementValidator.js
+++ b/src/isomorphic/classic/element/ReactElementValidator.js
@@ -30,8 +30,8 @@ var getIteratorFn = require('getIteratorFn');
if (__DEV__) {
var warning = require('fbjs/lib/warning');
var ReactDebugCurrentFrame = require('ReactDebugCurrentFrame');
- var {
- getCurrentStackAddendum,
+ var {
+ getCurrentStackAddendum,
} = require('ReactComponentTreeHook');
}
@@ -70,8 +70,9 @@ function getCurrentComponentErrorInfo(parentType) {
var info = getDeclarationErrorAddendum();
if (!info) {
- var parentName = typeof parentType === 'string' ?
- parentType : parentType.displayName || parentType.name;
+ var parentName = typeof parentType === 'string'
+ ? parentType
+ : parentType.displayName || parentType.name;
if (parentName) {
info = `\n\nCheck the top-level render call using <${parentName}>.`;
}
@@ -96,9 +97,8 @@ function validateExplicitKey(element, parentType) {
}
element._store.validated = true;
- var memoizer = ownerHasKeyUseWarning.uniqueKey || (
- ownerHasKeyUseWarning.uniqueKey = {}
- );
+ var memoizer = ownerHasKeyUseWarning.uniqueKey ||
+ (ownerHasKeyUseWarning.uniqueKey = {});
var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
if (memoizer[currentComponentErrorInfo]) {
@@ -110,21 +110,20 @@ function validateExplicitKey(element, parentType) {
// property, it may be the creator of the child that's responsible for
// assigning it a key.
var childOwner = '';
- if (element &&
- element._owner &&
- element._owner !== ReactCurrentOwner.current) {
+ if (
+ element && element._owner && element._owner !== ReactCurrentOwner.current
+ ) {
// Give the component that originally created this child.
- childOwner =
- ` It was passed a child from ${getComponentName(element._owner)}.`;
+ childOwner = ` It was passed a child from ${getComponentName(element._owner)}.`;
}
warning(
false,
'Each child in an array or iterator should have a unique "key" prop.' +
- '%s%s See https://fb.me/react-warning-keys for more information.%s',
+ '%s%s See https://fb.me/react-warning-keys for more information.%s',
currentComponentErrorInfo,
childOwner,
- getCurrentStackAddendum(element)
+ getCurrentStackAddendum(element),
);
}
@@ -183,41 +182,32 @@ function validatePropTypes(element) {
}
var name = componentClass.displayName || componentClass.name;
if (componentClass.propTypes) {
- checkReactTypeSpec(
- componentClass.propTypes,
- element.props,
- 'prop',
- name
- );
+ checkReactTypeSpec(componentClass.propTypes, element.props, 'prop', name);
}
if (typeof componentClass.getDefaultProps === 'function') {
warning(
componentClass.getDefaultProps.isReactClassApproved,
'getDefaultProps is only used on classic React.createClass ' +
- 'definitions. Use a static property named `defaultProps` instead.'
+ 'definitions. Use a static property named `defaultProps` instead.',
);
}
}
var ReactElementValidator = {
-
createElement: function(type, props, children) {
- var validType =
- typeof type === 'string' ||
- typeof type === 'function';
+ var validType = typeof type === 'string' || typeof type === 'function';
// We warn in this case but don't throw. We expect the element creation to
// succeed and there will likely be errors in render.
if (!validType) {
var info = '';
if (
type === undefined ||
- typeof type === 'object' &&
- type !== null &&
- Object.keys(type).length === 0
+ (typeof type === 'object' &&
+ type !== null &&
+ Object.keys(type).length === 0)
) {
- info +=
- ' You likely forgot to export your component from the file ' +
- 'it\'s defined in.';
+ info += ' You likely forgot to export your component from the file ' +
+ "it's defined in.";
}
var sourceInfo = getSourceInfoErrorAddendum(props);
@@ -232,8 +222,8 @@ var ReactElementValidator = {
warning(
false,
'React.createElement: type is invalid -- expected a string (for ' +
- 'built-in components) or a class/function (for composite ' +
- 'components) but got: %s.%s',
+ 'built-in components) or a class/function (for composite ' +
+ 'components) but got: %s.%s',
type == null ? type : typeof type,
info,
);
@@ -272,37 +262,29 @@ var ReactElementValidator = {
},
createFactory: function(type) {
- var validatedFactory = ReactElementValidator.createElement.bind(
- null,
- type
- );
+ var validatedFactory = ReactElementValidator.createElement.bind(null, type);
// Legacy hook TODO: Warn if this is accessed
validatedFactory.type = type;
if (__DEV__) {
if (canDefineProperty) {
- Object.defineProperty(
- validatedFactory,
- 'type',
- {
- enumerable: false,
- get: function() {
- warning(
- false,
- 'Factory.type is deprecated. Access the class directly ' +
- 'before passing it to createFactory.'
- );
- Object.defineProperty(this, 'type', {
- value: type,
- });
- return type;
- },
- }
- );
+ Object.defineProperty(validatedFactory, 'type', {
+ enumerable: false,
+ get: function() {
+ warning(
+ false,
+ 'Factory.type is deprecated. Access the class directly ' +
+ 'before passing it to createFactory.',
+ );
+ Object.defineProperty(this, 'type', {
+ value: type,
+ });
+ return type;
+ },
+ });
}
}
-
return validatedFactory;
},
@@ -320,7 +302,6 @@ var ReactElementValidator = {
}
return newElement;
},
-
};
module.exports = ReactElementValidator;
diff --git a/src/isomorphic/classic/element/__tests__/ReactElement-test.js b/src/isomorphic/classic/element/__tests__/ReactElement-test.js
index a7967be465..27bd222be8 100644
--- a/src/isomorphic/classic/element/__tests__/ReactElement-test.js
+++ b/src/isomorphic/classic/element/__tests__/ReactElement-test.js
@@ -83,9 +83,9 @@ describe('ReactElement', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(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 ' +
- 'prop. (https://fb.me/react-special-props)'
+ 'in `undefined` being returned. If you need to access the same ' +
+ 'value within the child component, you should pass it as a different ' +
+ 'prop. (https://fb.me/react-special-props)',
);
});
@@ -113,9 +113,9 @@ describe('ReactElement', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(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 ' +
- 'prop. (https://fb.me/react-special-props)'
+ 'in `undefined` being returned. If you need to access the same ' +
+ 'value within the child component, you should pass it as a different ' +
+ 'prop. (https://fb.me/react-special-props)',
);
});
@@ -127,9 +127,9 @@ describe('ReactElement', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'div: `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 ' +
- 'prop. (https://fb.me/react-special-props)'
+ 'in `undefined` being returned. If you need to access the same ' +
+ 'value within the child component, you should pass it as a different ' +
+ 'prop. (https://fb.me/react-special-props)',
);
});
@@ -155,9 +155,9 @@ describe('ReactElement', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(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 ' +
- 'prop. (https://fb.me/react-special-props)'
+ 'in `undefined` being returned. If you need to access the same ' +
+ 'value within the child component, you should pass it as a different ' +
+ 'prop. (https://fb.me/react-special-props)',
);
});
@@ -265,7 +265,7 @@ describe('ReactElement', () => {
});
var instance = ReactTestUtils.renderIntoDocument(
- React.createElement(Wrapper)
+ React.createElement(Wrapper),
);
if (ReactDOMFeatureFlags.useFiber) {
@@ -278,9 +278,12 @@ describe('ReactElement', () => {
it('merges an additional argument onto the children prop', () => {
spyOn(console, 'error');
var a = 1;
- var element = React.createFactory(ComponentClass)({
- children: 'text',
- }, a);
+ var element = React.createFactory(ComponentClass)(
+ {
+ children: 'text',
+ },
+ a,
+ );
expect(element.props.children).toBe(a);
expectDev(console.error.calls.count()).toBe(0);
});
@@ -296,9 +299,12 @@ describe('ReactElement', () => {
it('overrides children if null is provided as an argument', () => {
spyOn(console, 'error');
- var element = React.createFactory(ComponentClass)({
- children: 'text',
- }, null);
+ var element = React.createFactory(ComponentClass)(
+ {
+ children: 'text',
+ },
+ null,
+ );
expect(element.props.children).toBe(null);
expectDev(console.error.calls.count()).toBe(0);
});
@@ -346,10 +352,8 @@ describe('ReactElement', () => {
},
});
- expect(React.isValidElement(React.createElement('div')))
- .toEqual(true);
- expect(React.isValidElement(React.createElement(Component)))
- .toEqual(true);
+ expect(React.isValidElement(React.createElement('div'))).toEqual(true);
+ expect(React.isValidElement(React.createElement(Component))).toEqual(true);
expect(React.isValidElement(null)).toEqual(false);
expect(React.isValidElement(true)).toEqual(false);
@@ -357,7 +361,7 @@ describe('ReactElement', () => {
expect(React.isValidElement('string')).toEqual(false);
expect(React.isValidElement(React.DOM.div)).toEqual(false);
expect(React.isValidElement(Component)).toEqual(false);
- expect(React.isValidElement({ type: 'div', props: {} })).toEqual(false);
+ expect(React.isValidElement({type: 'div', props: {}})).toEqual(false);
var jsonElement = JSON.stringify(React.createElement('div'));
expect(React.isValidElement(JSON.parse(jsonElement))).toBe(true);
@@ -401,7 +405,7 @@ describe('ReactElement', () => {
var container = document.createElement('div');
var instance = ReactDOM.render(
React.createElement(Component, {fruit: 'mango'}),
- container
+ container,
);
expect(instance.props.fruit).toBe('mango');
@@ -422,12 +426,12 @@ describe('ReactElement', () => {
});
var instance = ReactTestUtils.renderIntoDocument(
- React.createElement(Component)
+ React.createElement(Component),
);
expect(instance.props.prop).toBe('testKey');
var inst2 = ReactTestUtils.renderIntoDocument(
- React.createElement(Component, {prop: null})
+ React.createElement(Component, {prop: null}),
);
expect(inst2.props.prop).toBe(null);
});
@@ -510,10 +514,8 @@ describe('ReactElement', () => {
},
});
- expect(React.isValidElement(React.createElement('div')))
- .toEqual(true);
- expect(React.isValidElement(React.createElement(Component)))
- .toEqual(true);
+ expect(React.isValidElement(React.createElement('div'))).toEqual(true);
+ expect(React.isValidElement(React.createElement(Component))).toEqual(true);
expect(React.isValidElement(null)).toEqual(false);
expect(React.isValidElement(true)).toEqual(false);
@@ -521,12 +523,11 @@ describe('ReactElement', () => {
expect(React.isValidElement('string')).toEqual(false);
expect(React.isValidElement(React.DOM.div)).toEqual(false);
expect(React.isValidElement(Component)).toEqual(false);
- expect(React.isValidElement({ type: 'div', props: {} })).toEqual(false);
+ expect(React.isValidElement({type: 'div', props: {}})).toEqual(false);
var jsonElement = JSON.stringify(React.createElement('div'));
expect(React.isValidElement(JSON.parse(jsonElement))).toBe(false);
});
-
});
describe('comparing jsx vs .createFactory() vs .createElement()', () => {
@@ -540,7 +541,6 @@ describe('comparing jsx vs .createFactory() vs .createElement()', () => {
Child = jest.genMockFromModule('ReactElementTestChild');
});
-
describe('when using jsx only', () => {
var Parent, instance;
beforeEach(() => {
@@ -557,7 +557,10 @@ describe('comparing jsx vs .createFactory() vs .createElement()', () => {
});
it('should scry children but cannot', () => {
- var children = ReactTestUtils.scryRenderedComponentsWithType(instance, Child);
+ var children = ReactTestUtils.scryRenderedComponentsWithType(
+ instance,
+ Child,
+ );
expect(children.length).toBe(1);
});
@@ -566,7 +569,10 @@ describe('comparing jsx vs .createFactory() vs .createElement()', () => {
});
it('can capture Child instantiation calls', () => {
- expect(Child.mock.calls[0][0]).toEqual({ foo: 'foo value', children: 'children value' });
+ expect(Child.mock.calls[0][0]).toEqual({
+ foo: 'foo value',
+ children: 'children value',
+ });
});
});
@@ -576,7 +582,10 @@ describe('comparing jsx vs .createFactory() vs .createElement()', () => {
var childFactory = React.createFactory(Child);
var Parent = React.createClass({
render: function() {
- return React.DOM.div({}, childFactory({ ref: 'child', foo: 'foo value' }, 'children value'));
+ return React.DOM.div(
+ {},
+ childFactory({ref: 'child', foo: 'foo value'}, 'children value'),
+ );
},
});
factory = React.createFactory(Parent);
@@ -584,7 +593,10 @@ describe('comparing jsx vs .createFactory() vs .createElement()', () => {
});
it('can properly scry children', () => {
- var children = ReactTestUtils.scryRenderedComponentsWithType(instance, Child);
+ var children = ReactTestUtils.scryRenderedComponentsWithType(
+ instance,
+ Child,
+ );
expect(children.length).toBe(1);
});
@@ -593,7 +605,10 @@ describe('comparing jsx vs .createFactory() vs .createElement()', () => {
});
it('can capture Child instantiation calls', () => {
- expect(Child.mock.calls[0][0]).toEqual({ foo: 'foo value', children: 'children value' });
+ expect(Child.mock.calls[0][0]).toEqual({
+ foo: 'foo value',
+ children: 'children value',
+ });
});
});
@@ -602,7 +617,14 @@ describe('comparing jsx vs .createFactory() vs .createElement()', () => {
beforeEach(() => {
var Parent = React.createClass({
render: function() {
- return React.DOM.div({}, React.createElement(Child, { ref: 'child', foo: 'foo value' }, 'children value'));
+ return React.DOM.div(
+ {},
+ React.createElement(
+ Child,
+ {ref: 'child', foo: 'foo value'},
+ 'children value',
+ ),
+ );
},
});
factory = React.createFactory(Parent);
@@ -610,7 +632,10 @@ describe('comparing jsx vs .createFactory() vs .createElement()', () => {
});
it('should scry children but cannot', () => {
- var children = ReactTestUtils.scryRenderedComponentsWithType(instance, Child);
+ var children = ReactTestUtils.scryRenderedComponentsWithType(
+ instance,
+ Child,
+ );
expect(children.length).toBe(1);
});
@@ -619,8 +644,10 @@ describe('comparing jsx vs .createFactory() vs .createElement()', () => {
});
it('can capture Child instantiation calls', () => {
- expect(Child.mock.calls[0][0]).toEqual({ foo: 'foo value', children: 'children value' });
+ expect(Child.mock.calls[0][0]).toEqual({
+ foo: 'foo value',
+ children: 'children value',
+ });
});
});
-
});
diff --git a/src/isomorphic/classic/element/__tests__/ReactElementClone-test.js b/src/isomorphic/classic/element/__tests__/ReactElementClone-test.js
index 38ef248683..b4eaaa0765 100644
--- a/src/isomorphic/classic/element/__tests__/ReactElementClone-test.js
+++ b/src/isomorphic/classic/element/__tests__/ReactElementClone-test.js
@@ -42,7 +42,7 @@ describe('ReactElementClone', () => {
render: function() {
return (
- {React.cloneElement(this.props.child, { className: 'xyz' })}
+ {React.cloneElement(this.props.child, {className: 'xyz'})}
);
},
@@ -66,7 +66,7 @@ describe('ReactElementClone', () => {
render: function() {
return (
- {React.cloneElement(this.props.child, { className: 'xyz' })}
+ {React.cloneElement(this.props.child, {className: 'xyz'})}
);
},
@@ -91,7 +91,7 @@ describe('ReactElementClone', () => {
render: function() {
return (
- {React.cloneElement(this.props.child, { className: 'xyz' })}
+ {React.cloneElement(this.props.child, {className: 'xyz'})}
);
},
@@ -120,7 +120,7 @@ describe('ReactElementClone', () => {
});
ReactTestUtils.renderIntoDocument(
- React.cloneElement(
, {children: 'xyz'})
+ React.cloneElement(
, {children: 'xyz'}),
);
});
@@ -133,7 +133,7 @@ describe('ReactElementClone', () => {
});
ReactTestUtils.renderIntoDocument(
- React.cloneElement(
xyz, {})
+ React.cloneElement(
xyz, {}),
);
});
@@ -146,34 +146,41 @@ describe('ReactElementClone', () => {
var clone = React.cloneElement(
xyz,
- { children:
},
-
,
-
- );
-
- expect(clone.props.children).toEqual([
+ {children:
},
,
,
- ]);
+ );
+
+ expect(clone.props.children).toEqual([
,
]);
});
it('should override children if undefined is provided as an argument', () => {
- var element = React.createElement(ComponentClass, {
- children: 'text',
- }, undefined);
+ var element = React.createElement(
+ ComponentClass,
+ {
+ children: 'text',
+ },
+ undefined,
+ );
expect(element.props.children).toBe(undefined);
- var element2 = React.cloneElement(React.createElement(ComponentClass, {
- children: 'text',
- }), {}, undefined);
+ var element2 = React.cloneElement(
+ React.createElement(ComponentClass, {
+ children: 'text',
+ }),
+ {},
+ undefined,
+ );
expect(element2.props.children).toBe(undefined);
});
it('should support keys and refs', () => {
var Parent = React.createClass({
render: function() {
- var clone =
- React.cloneElement(this.props.children, {key: 'xyz', ref: 'xyz'});
+ var clone = React.cloneElement(this.props.children, {
+ key: 'xyz',
+ ref: 'xyz',
+ });
expect(clone.key).toBe('xyz');
expect(clone.ref).toBe('xyz');
return
{clone}
;
@@ -218,7 +225,7 @@ describe('ReactElementClone', () => {
});
ReactTestUtils.renderIntoDocument(
- React.cloneElement(
, {myprop: 'xyz'})
+ React.cloneElement(
, {myprop: 'xyz'}),
);
});
@@ -252,7 +259,7 @@ describe('ReactElementClone', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
- 'Each child in an array or iterator should have a unique "key" prop.'
+ 'Each child in an array or iterator should have a unique "key" prop.',
);
});
@@ -297,21 +304,20 @@ describe('ReactElementClone', () => {
});
var GrandParent = React.createClass({
render: function() {
- return React.createElement(
- Parent,
- { child: React.createElement(Component, {color: 'red'}) }
- );
+ return React.createElement(Parent, {
+ child: React.createElement(Component, {color: 'red'}),
+ });
},
});
ReactTestUtils.renderIntoDocument(React.createElement(GrandParent));
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Failed prop type: ' +
- 'Invalid prop `color` of type `number` supplied to `Component`, ' +
- 'expected `string`.\n' +
- ' in Component (created by GrandParent)\n' +
- ' in Parent (created by GrandParent)\n' +
- ' in GrandParent'
+ 'Invalid prop `color` of type `number` supplied to `Component`, ' +
+ 'expected `string`.\n' +
+ ' in Component (created by GrandParent)\n' +
+ ' in Parent (created by GrandParent)\n' +
+ ' in GrandParent',
);
});
@@ -361,5 +367,4 @@ describe('ReactElementClone', () => {
expect(Object.isFrozen(element.props)).toBe(true);
expect(clone.props).toEqual({foo: 'ef'});
});
-
});
diff --git a/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js b/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js
index 34fe5b3a62..c9dbf7cc8f 100644
--- a/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js
+++ b/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js
@@ -46,7 +46,7 @@ describe('ReactElementValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
- 'Each child in an array or iterator should have a unique "key" prop.'
+ 'Each child in an array or iterator should have a unique "key" prop.',
);
});
@@ -66,19 +66,17 @@ describe('ReactElementValidator', () => {
var ComponentWrapper = React.createClass({
displayName: 'ComponentWrapper',
render: function() {
- return InnerComponent({childSet: [Component(), Component()] });
+ return InnerComponent({childSet: [Component(), Component()]});
},
});
- ReactTestUtils.renderIntoDocument(
- React.createElement(ComponentWrapper)
- );
+ ReactTestUtils.renderIntoDocument(React.createElement(ComponentWrapper));
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Each child in an array or iterator should have a unique "key" prop.' +
- '\n\nCheck the render method of `InnerClass`. ' +
- 'It was passed a child from ComponentWrapper. '
+ '\n\nCheck the render method of `InnerClass`. ' +
+ 'It was passed a child from ComponentWrapper. ',
);
});
@@ -92,35 +90,29 @@ describe('ReactElementValidator', () => {
},
});
- var divs = [
-
,
-
,
- ];
+ var divs = [
,
];
ReactTestUtils.renderIntoDocument(
{divs});
expectDev(console.error.calls.count()).toBe(1);
expectDev(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 **)'
+ '"key" prop. See https://fb.me/react-warning-keys for more information.\n' +
+ ' in div (at **)',
);
});
it('warns for keys for arrays of elements with no owner info', () => {
spyOn(console, 'error');
- var divs = [
-
,
-
,
- ];
+ var divs = [
,
];
ReactTestUtils.renderIntoDocument(
{divs}
);
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Each child in an array or iterator should have a unique ' +
- '"key" prop.\n\nCheck the top-level render call using
. See ' +
- 'https://fb.me/react-warning-keys for more information.\n' +
- ' in div (at **)'
+ '"key" prop.\n\nCheck the top-level render call using
. See ' +
+ 'https://fb.me/react-warning-keys for more information.\n' +
+ ' in div (at **)',
);
});
@@ -150,12 +142,12 @@ describe('ReactElementValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Each child in an array or iterator should have a unique ' +
- '"key" prop.\n\nCheck the render method of `Component`. See ' +
- 'https://fb.me/react-warning-keys for more information.\n' +
- ' in div (at **)\n' +
- ' in Component (at **)\n' +
- ' in Parent (at **)\n' +
- ' in GrandParent (at **)'
+ '"key" prop.\n\nCheck the render method of `Component`. See ' +
+ 'https://fb.me/react-warning-keys for more information.\n' +
+ ' in div (at **)\n' +
+ ' in Component (at **)\n' +
+ ' in Parent (at **)\n' +
+ ' in GrandParent (at **)',
);
});
@@ -177,7 +169,7 @@ describe('ReactElementValidator', () => {
-
+ ,
);
expectDev(console.error.calls.count()).toBe(0);
@@ -203,7 +195,7 @@ describe('ReactElementValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
- 'Each child in an array or iterator should have a unique "key" prop.'
+ 'Each child in an array or iterator should have a unique "key" prop.',
);
});
@@ -279,10 +271,10 @@ describe('ReactElementValidator', () => {
ReactTestUtils.renderIntoDocument(React.createElement(ParentComp));
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Failed prop type: ' +
- 'Invalid prop `color` of type `number` supplied to `MyComp`, ' +
- 'expected `string`.\n' +
- ' in MyComp (created by ParentComp)\n' +
- ' in ParentComp'
+ 'Invalid prop `color` of type `number` supplied to `MyComp`, ' +
+ 'expected `string`.\n' +
+ ' in MyComp (created by ParentComp)\n' +
+ ' in ParentComp',
);
});
@@ -297,35 +289,35 @@ describe('ReactElementValidator', () => {
expectDev(console.error.calls.count()).toBe(6);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: React.createElement: type is invalid -- expected a string ' +
- '(for built-in components) or a class/function (for composite ' +
- 'components) but got: undefined. You likely forgot to export your ' +
- 'component from the file it\'s defined in.'
+ '(for built-in components) or a class/function (for composite ' +
+ 'components) but got: undefined. You likely forgot to export your ' +
+ "component from the file it's defined in.",
);
expectDev(console.error.calls.argsFor(1)[0]).toBe(
'Warning: React.createElement: type is invalid -- expected a string ' +
- '(for built-in components) or a class/function (for composite ' +
- 'components) but got: null.'
+ '(for built-in components) or a class/function (for composite ' +
+ 'components) but got: null.',
);
expectDev(console.error.calls.argsFor(2)[0]).toBe(
'Warning: React.createElement: type is invalid -- expected a string ' +
- '(for built-in components) or a class/function (for composite ' +
- 'components) but got: boolean.'
+ '(for built-in components) or a class/function (for composite ' +
+ 'components) but got: boolean.',
);
expectDev(console.error.calls.argsFor(3)[0]).toBe(
'Warning: React.createElement: type is invalid -- expected a string ' +
- '(for built-in components) or a class/function (for composite ' +
- 'components) but got: number.'
+ '(for built-in components) or a class/function (for composite ' +
+ 'components) but got: number.',
);
expectDev(console.error.calls.argsFor(4)[0]).toBe(
'Warning: React.createElement: type is invalid -- expected a string ' +
- '(for built-in components) or a class/function (for composite ' +
- 'components) but got: object.'
+ '(for built-in components) or a class/function (for composite ' +
+ 'components) but got: object.',
);
expectDev(console.error.calls.argsFor(5)[0]).toBe(
'Warning: React.createElement: type is invalid -- expected a string ' +
- '(for built-in components) or a class/function (for composite ' +
- 'components) but got: object. You likely forgot to export your ' +
- 'component from the file it\'s defined in.'
+ '(for built-in components) or a class/function (for composite ' +
+ 'components) but got: object. You likely forgot to export your ' +
+ "component from the file it's defined in.",
);
React.createElement('div');
expectDev(console.error.calls.count()).toBe(6);
@@ -342,15 +334,15 @@ describe('ReactElementValidator', () => {
ReactTestUtils.renderIntoDocument(React.createElement(ParentComp));
}).toThrowError(
'Element type is invalid: expected a string (for built-in components) ' +
- 'or a class/function (for composite components) but got: null.\n\nCheck ' +
- 'the render method of `ParentComp`.'
+ 'or a class/function (for composite components) but got: null.\n\nCheck ' +
+ 'the render method of `ParentComp`.',
);
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: React.createElement: type is invalid -- expected a string ' +
- '(for built-in components) or a class/function (for composite ' +
- 'components) but got: null.\n\nCheck the render method of `ParentComp`.' +
- '\n in ParentComp'
+ '(for built-in components) or a class/function (for composite ' +
+ 'components) but got: null.\n\nCheck the render method of `ParentComp`.' +
+ '\n in ParentComp',
);
});
@@ -372,8 +364,8 @@ describe('ReactElementValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Failed prop type: The prop `prop` is marked as required in ' +
- '`Component`, but its value is `null`.\n' +
- ' in Component'
+ '`Component`, but its value is `null`.\n' +
+ ' in Component',
);
});
@@ -391,14 +383,14 @@ describe('ReactElementValidator', () => {
});
ReactTestUtils.renderIntoDocument(
- React.createElement(Component, {prop:null})
+ React.createElement(Component, {prop: null}),
);
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Failed prop type: The prop `prop` is marked as required in ' +
- '`Component`, but its value is `null`.\n' +
- ' in Component'
+ '`Component`, but its value is `null`.\n' +
+ ' in Component',
);
});
@@ -414,30 +406,28 @@ describe('ReactElementValidator', () => {
},
});
+ ReactTestUtils.renderIntoDocument(React.createElement(Component));
ReactTestUtils.renderIntoDocument(
- React.createElement(Component)
- );
- ReactTestUtils.renderIntoDocument(
- React.createElement(Component, {prop: 42})
+ React.createElement(Component, {prop: 42}),
);
expectDev(console.error.calls.count()).toBe(2);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Failed prop type: ' +
- 'The prop `prop` is marked as required in `Component`, but its value ' +
- 'is `undefined`.\n' +
- ' in Component'
+ 'The prop `prop` is marked as required in `Component`, but its value ' +
+ 'is `undefined`.\n' +
+ ' in Component',
);
expectDev(console.error.calls.argsFor(1)[0]).toBe(
'Warning: Failed prop type: ' +
- 'Invalid prop `prop` of type `number` supplied to ' +
- '`Component`, expected `string`.\n' +
- ' in Component'
+ 'Invalid prop `prop` of type `number` supplied to ' +
+ '`Component`, expected `string`.\n' +
+ ' in Component',
);
ReactTestUtils.renderIntoDocument(
- React.createElement(Component, {prop: 'string'})
+ React.createElement(Component, {prop: 'string'}),
);
// Should not error for strings
@@ -457,16 +447,16 @@ describe('ReactElementValidator', () => {
});
ReactTestUtils.renderIntoDocument(
- React.createElement(Component, {myProp: {value: 'hi'}})
+ React.createElement(Component, {myProp: {value: 'hi'}}),
);
expectDev(console.error.calls.count()).toBe(1);
expectDev(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 ' +
- 'the type checker creator (arrayOf, instanceOf, objectOf, oneOf, ' +
- 'oneOfType, and shape all require an argument).'
+ 'the type checker function must return `null` or an `Error` but ' +
+ 'returned a function. You may have forgotten to pass an argument to ' +
+ 'the type checker creator (arrayOf, instanceOf, objectOf, oneOf, ' +
+ 'oneOfType, and shape all require an argument).',
);
});
@@ -482,7 +472,7 @@ describe('ReactElementValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Factory.type is deprecated. Access the class directly before ' +
- 'passing it to createFactory.'
+ 'passing it to createFactory.',
);
// Warn once, not again
expect(TestFactory.type).toBe(TestComponent);
@@ -531,7 +521,7 @@ describe('ReactElementValidator', () => {
// shouldn't blow up either.
var child = {
- $$typeof: (
).$$typeof,
+ $$typeof:
.$$typeof,
type: 'span',
key: null,
ref: null,
@@ -549,10 +539,9 @@ describe('ReactElementValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: React.createElement: type is invalid -- expected a string ' +
- '(for built-in components) or a class/function (for composite ' +
- 'components) but got: undefined. You likely forgot to export your ' +
- 'component from the file it\'s defined in.\n\nCheck your code at **.'
+ '(for built-in components) or a class/function (for composite ' +
+ 'components) but got: undefined. You likely forgot to export your ' +
+ "component from the file it's defined in.\n\nCheck your code at **.",
);
});
-
});
diff --git a/src/isomorphic/classic/types/ReactPropTypes.js b/src/isomorphic/classic/types/ReactPropTypes.js
index 6cd3c04d93..01710a0086 100644
--- a/src/isomorphic/classic/types/ReactPropTypes.js
+++ b/src/isomorphic/classic/types/ReactPropTypes.js
@@ -95,7 +95,7 @@ if (__DEV__) {
var productionTypeChecker = function() {
invariant(
false,
- 'React.PropTypes type checking code is stripped in production.'
+ 'React.PropTypes type checking code is stripped in production.',
);
};
productionTypeChecker.isRequired = productionTypeChecker;
@@ -122,7 +122,6 @@ if (__DEV__) {
};
}
-
/**
* inlined Object.is polyfill to avoid requiring consumers ship their own
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
@@ -130,7 +129,8 @@ if (__DEV__) {
/*eslint-disable no-self-compare*/
function is(x, y) {
// SameValue algorithm
- if (x === y) { // Steps 1-5, 7-10
+ if (x === y) {
+ // Steps 1-5, 7-10
// Steps 6.b-6.e: +0 != -0
return x !== 0 || 1 / x === 1 / y;
} else {
@@ -165,27 +165,24 @@ function createChainableTypeChecker(validate) {
componentName,
location,
propFullName,
- secret
+ secret,
) {
componentName = componentName || ANONYMOUS;
propFullName = propFullName || propName;
if (__DEV__) {
- if (
- secret !== ReactPropTypesSecret &&
- typeof console !== 'undefined'
- ) {
+ if (secret !== ReactPropTypesSecret && typeof console !== 'undefined') {
var cacheKey = `${componentName}:${propName}`;
if (!manualPropTypeCallCache[cacheKey]) {
warning(
false,
'You are manually calling a React.PropTypes validation ' +
- 'function for the `%s` prop on `%s`. This is deprecated ' +
- 'and will not work in production with the next major version. ' +
- 'You may be seeing this warning due to a third-party PropTypes ' +
- 'library. See https://fb.me/react-warning-dont-call-proptypes ' +
- 'for details.',
+ 'function for the `%s` prop on `%s`. This is deprecated ' +
+ 'and will not work in production with the next major version. ' +
+ 'You may be seeing this warning due to a third-party PropTypes ' +
+ 'library. See https://fb.me/react-warning-dont-call-proptypes ' +
+ 'for details.',
propFullName,
- componentName
+ componentName,
);
manualPropTypeCallCache[cacheKey] = true;
}
@@ -196,23 +193,17 @@ function createChainableTypeChecker(validate) {
if (props[propName] === null) {
return new PropTypeError(
`The ${location} \`${propFullName}\` is marked as required ` +
- `in \`${componentName}\`, but its value is \`null\`.`
+ `in \`${componentName}\`, but its value is \`null\`.`,
);
}
return new PropTypeError(
`The ${location} \`${propFullName}\` is marked as required in ` +
- `\`${componentName}\`, but its value is \`undefined\`.`
+ `\`${componentName}\`, but its value is \`undefined\`.`,
);
}
return null;
} else {
- return validate(
- props,
- propName,
- componentName,
- location,
- propFullName,
- );
+ return validate(props, propName, componentName, location, propFullName);
}
}
@@ -229,7 +220,7 @@ function createPrimitiveTypeChecker(expectedType) {
componentName,
location,
propFullName,
- secret
+ secret,
) {
var propValue = props[propName];
var propType = getPropType(propValue);
@@ -241,8 +232,8 @@ function createPrimitiveTypeChecker(expectedType) {
return new PropTypeError(
`Invalid ${location} \`${propFullName}\` of type ` +
- `\`${preciseType}\` supplied to \`${componentName}\`, expected ` +
- `\`${expectedType}\`.`
+ `\`${preciseType}\` supplied to \`${componentName}\`, expected ` +
+ `\`${expectedType}\`.`,
);
}
return null;
@@ -258,7 +249,7 @@ function createArrayOfTypeChecker(typeChecker) {
function validate(props, propName, componentName, location, propFullName) {
if (typeof typeChecker !== 'function') {
return new PropTypeError(
- `Property \`${propFullName}\` of component \`${componentName}\` has invalid PropType notation inside arrayOf.`
+ `Property \`${propFullName}\` of component \`${componentName}\` has invalid PropType notation inside arrayOf.`,
);
}
var propValue = props[propName];
@@ -266,7 +257,7 @@ function createArrayOfTypeChecker(typeChecker) {
var propType = getPropType(propValue);
return new PropTypeError(
`Invalid ${location} \`${propFullName}\` of type ` +
- `\`${propType}\` supplied to \`${componentName}\`, expected an array.`
+ `\`${propType}\` supplied to \`${componentName}\`, expected an array.`,
);
}
for (var i = 0; i < propValue.length; i++) {
@@ -276,7 +267,7 @@ function createArrayOfTypeChecker(typeChecker) {
componentName,
location,
`${propFullName}[${i}]`,
- ReactPropTypesSecret
+ ReactPropTypesSecret,
);
if (error instanceof Error) {
return error;
@@ -294,7 +285,7 @@ function createElementTypeChecker() {
var propType = getPropType(propValue);
return new PropTypeError(
`Invalid ${location} \`${propFullName}\` of type ` +
- `\`${propType}\` supplied to \`${componentName}\`, expected a single ReactElement.`
+ `\`${propType}\` supplied to \`${componentName}\`, expected a single ReactElement.`,
);
}
return null;
@@ -309,8 +300,8 @@ function createInstanceTypeChecker(expectedClass) {
var actualClassName = getClassName(props[propName]);
return new PropTypeError(
`Invalid ${location} \`${propFullName}\` of type ` +
- `\`${actualClassName}\` supplied to \`${componentName}\`, expected ` +
- `instance of \`${expectedClassName}\`.`
+ `\`${actualClassName}\` supplied to \`${componentName}\`, expected ` +
+ `instance of \`${expectedClassName}\`.`,
);
}
return null;
@@ -320,7 +311,10 @@ function createInstanceTypeChecker(expectedClass) {
function createEnumTypeChecker(expectedValues) {
if (!Array.isArray(expectedValues)) {
- warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.');
+ warning(
+ false,
+ 'Invalid argument supplied to oneOf, expected an instance of array.',
+ );
return emptyFunction.thatReturnsNull;
}
@@ -335,7 +329,7 @@ function createEnumTypeChecker(expectedValues) {
var valuesString = JSON.stringify(expectedValues);
return new PropTypeError(
`Invalid ${location} \`${propFullName}\` of value \`${propValue}\` ` +
- `supplied to \`${componentName}\`, expected one of ${valuesString}.`
+ `supplied to \`${componentName}\`, expected one of ${valuesString}.`,
);
}
return createChainableTypeChecker(validate);
@@ -345,7 +339,7 @@ function createObjectOfTypeChecker(typeChecker) {
function validate(props, propName, componentName, location, propFullName) {
if (typeof typeChecker !== 'function') {
return new PropTypeError(
- `Property \`${propFullName}\` of component \`${componentName}\` has invalid PropType notation inside objectOf.`
+ `Property \`${propFullName}\` of component \`${componentName}\` has invalid PropType notation inside objectOf.`,
);
}
var propValue = props[propName];
@@ -353,7 +347,7 @@ function createObjectOfTypeChecker(typeChecker) {
if (propType !== 'object') {
return new PropTypeError(
`Invalid ${location} \`${propFullName}\` of type ` +
- `\`${propType}\` supplied to \`${componentName}\`, expected an object.`
+ `\`${propType}\` supplied to \`${componentName}\`, expected an object.`,
);
}
for (var key in propValue) {
@@ -364,7 +358,7 @@ function createObjectOfTypeChecker(typeChecker) {
componentName,
location,
`${propFullName}.${key}`,
- ReactPropTypesSecret
+ ReactPropTypesSecret,
);
if (error instanceof Error) {
return error;
@@ -378,7 +372,10 @@ function createObjectOfTypeChecker(typeChecker) {
function createUnionTypeChecker(arrayOfTypeCheckers) {
if (!Array.isArray(arrayOfTypeCheckers)) {
- warning(false, 'Invalid argument supplied to oneOfType, expected an instance of array.');
+ warning(
+ false,
+ 'Invalid argument supplied to oneOfType, expected an instance of array.',
+ );
return emptyFunction.thatReturnsNull;
}
@@ -392,7 +389,7 @@ function createUnionTypeChecker(arrayOfTypeCheckers) {
componentName,
location,
propFullName,
- ReactPropTypesSecret
+ ReactPropTypesSecret,
) == null
) {
return null;
@@ -401,7 +398,7 @@ function createUnionTypeChecker(arrayOfTypeCheckers) {
return new PropTypeError(
`Invalid ${location} \`${propFullName}\` supplied to ` +
- `\`${componentName}\`.`
+ `\`${componentName}\`.`,
);
}
return createChainableTypeChecker(validate);
@@ -412,7 +409,7 @@ function createNodeChecker() {
if (!isNode(props[propName])) {
return new PropTypeError(
`Invalid ${location} \`${propFullName}\` supplied to ` +
- `\`${componentName}\`, expected a ReactNode.`
+ `\`${componentName}\`, expected a ReactNode.`,
);
}
return null;
@@ -427,7 +424,7 @@ function createShapeTypeChecker(shapeTypes) {
if (propType !== 'object') {
return new PropTypeError(
`Invalid ${location} \`${propFullName}\` of type \`${propType}\` ` +
- `supplied to \`${componentName}\`, expected \`object\`.`
+ `supplied to \`${componentName}\`, expected \`object\`.`,
);
}
for (var key in shapeTypes) {
@@ -441,7 +438,7 @@ function createShapeTypeChecker(shapeTypes) {
componentName,
location,
`${propFullName}.${key}`,
- ReactPropTypesSecret
+ ReactPropTypesSecret,
);
if (error) {
return error;
diff --git a/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js b/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
index 64dbe07ba3..c5ba572fb2 100644
--- a/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
+++ b/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
@@ -62,14 +62,22 @@ function typeCheckFailRequiredValues(declaration) {
var unspecifiedMsg = 'The prop `testProp` is marked as required in ' +
'`testComponent`, but its value is \`undefined\`.';
- var propTypes = { testProp: declaration };
+ var propTypes = {testProp: declaration};
// Required prop is null
- var message1 = getPropTypeWarningMessage(propTypes, { testProp: null }, 'testComponent');
+ var message1 = getPropTypeWarningMessage(
+ propTypes,
+ {testProp: null},
+ 'testComponent',
+ );
expect(message1).toContain(specifiedButIsNullMsg);
// Required prop is undefined
- var message2 = getPropTypeWarningMessage(propTypes, { testProp: undefined }, 'testComponent');
+ var message2 = getPropTypeWarningMessage(
+ propTypes,
+ {testProp: undefined},
+ 'testComponent',
+ );
expect(message2).toContain(unspecifiedMsg);
// Required prop is not a member of props object
@@ -93,16 +101,11 @@ function expectWarningInDevelopment(declaration, value) {
var propName = 'testProp' + Math.random().toString();
var componentName = 'testComponent' + Math.random().toString();
for (var i = 0; i < 3; i++) {
- declaration(
- props,
- propName,
- componentName,
- 'prop'
- );
+ declaration(props, propName, componentName, 'prop');
}
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
- 'You are manually calling a React.PropTypes validation '
+ 'You are manually calling a React.PropTypes validation ',
);
console.error.calls.reset();
}
@@ -124,8 +127,14 @@ describe('ReactPropTypes', () => {
return new Error('some error');
},
};
- const props = { foo: 'foo' };
- const returnValue = checkPropTypes(propTypes, props, 'prop', 'testComponent', null);
+ const props = {foo: 'foo'};
+ const returnValue = checkPropTypes(
+ propTypes,
+ props,
+ 'prop',
+ 'testComponent',
+ null,
+ );
expect(console.error.calls.argsFor(0)[0]).toContain('some error');
expect(returnValue).toBe(undefined);
});
@@ -137,8 +146,14 @@ describe('ReactPropTypes', () => {
throw new Error('some error');
},
};
- const props = { foo: 'foo' };
- const returnValue = checkPropTypes(propTypes, props, 'prop', 'testComponent', null);
+ const props = {foo: 'foo'};
+ const returnValue = checkPropTypes(
+ propTypes,
+ props,
+ 'prop',
+ 'testComponent',
+ null,
+ );
expect(console.error.calls.argsFor(0)[0]).toContain('some error');
expect(returnValue).toBe(undefined);
});
@@ -150,31 +165,31 @@ describe('ReactPropTypes', () => {
PropTypes.string,
[],
'Invalid prop `testProp` of type `array` supplied to ' +
- '`testComponent`, expected `string`.'
+ '`testComponent`, expected `string`.',
);
typeCheckFail(
PropTypes.string,
false,
'Invalid prop `testProp` of type `boolean` supplied to ' +
- '`testComponent`, expected `string`.'
+ '`testComponent`, expected `string`.',
);
typeCheckFail(
PropTypes.string,
0,
'Invalid prop `testProp` of type `number` supplied to ' +
- '`testComponent`, expected `string`.'
+ '`testComponent`, expected `string`.',
);
typeCheckFail(
PropTypes.string,
{},
'Invalid prop `testProp` of type `object` supplied to ' +
- '`testComponent`, expected `string`.'
+ '`testComponent`, expected `string`.',
);
typeCheckFail(
PropTypes.string,
Symbol(),
'Invalid prop `testProp` of type `symbol` supplied to ' +
- '`testComponent`, expected `string`.'
+ '`testComponent`, expected `string`.',
);
});
@@ -183,13 +198,13 @@ describe('ReactPropTypes', () => {
PropTypes.string,
new Date(),
'Invalid prop `testProp` of type `date` supplied to ' +
- '`testComponent`, expected `string`.'
+ '`testComponent`, expected `string`.',
);
typeCheckFail(
PropTypes.string,
/please/,
'Invalid prop `testProp` of type `regexp` supplied to ' +
- '`testComponent`, expected `string`.'
+ '`testComponent`, expected `string`.',
);
});
@@ -289,9 +304,9 @@ describe('ReactPropTypes', () => {
describe('ArrayOf Type', () => {
it('should fail for invalid argument', () => {
typeCheckFail(
- PropTypes.arrayOf({ foo: PropTypes.string }),
- { foo: 'bar' },
- 'Property `testProp` of component `testComponent` has invalid PropType notation inside arrayOf.'
+ PropTypes.arrayOf({foo: PropTypes.string}),
+ {foo: 'bar'},
+ 'Property `testProp` of component `testComponent` has invalid PropType notation inside arrayOf.',
);
});
@@ -305,14 +320,14 @@ describe('ReactPropTypes', () => {
it('should support arrayOf with complex types', () => {
typeCheckPass(
PropTypes.arrayOf(PropTypes.shape({a: PropTypes.number.isRequired})),
- [{a: 1}, {a: 2}]
+ [{a: 1}, {a: 2}],
);
function Thing() {}
- typeCheckPass(
- PropTypes.arrayOf(PropTypes.instanceOf(Thing)),
- [new Thing(), new Thing()]
- );
+ typeCheckPass(PropTypes.arrayOf(PropTypes.instanceOf(Thing)), [
+ new Thing(),
+ new Thing(),
+ ]);
});
it('should warn with invalid items in the array', () => {
@@ -320,7 +335,7 @@ describe('ReactPropTypes', () => {
PropTypes.arrayOf(PropTypes.number),
[1, 2, 'b'],
'Invalid prop `testProp[2]` of type `string` supplied to ' +
- '`testComponent`, expected `number`.'
+ '`testComponent`, expected `number`.',
);
});
@@ -332,7 +347,9 @@ describe('ReactPropTypes', () => {
PropTypes.arrayOf(PropTypes.instanceOf(Thing)),
[new Thing(), 'xyz'],
'Invalid prop `testProp[1]` of type `String` supplied to ' +
- '`testComponent`, expected instance of `' + name + '`.'
+ '`testComponent`, expected instance of `' +
+ name +
+ '`.',
);
});
@@ -341,19 +358,19 @@ describe('ReactPropTypes', () => {
PropTypes.arrayOf(PropTypes.number),
{'0': 'maybe-array', length: 1},
'Invalid prop `testProp` of type `object` supplied to ' +
- '`testComponent`, expected an array.'
+ '`testComponent`, expected an array.',
);
typeCheckFail(
PropTypes.arrayOf(PropTypes.number),
123,
'Invalid prop `testProp` of type `number` supplied to ' +
- '`testComponent`, expected an array.'
+ '`testComponent`, expected an array.',
);
typeCheckFail(
PropTypes.arrayOf(PropTypes.number),
'string',
'Invalid prop `testProp` of type `string` supplied to ' +
- '`testComponent`, expected an array.'
+ '`testComponent`, expected an array.',
);
});
@@ -368,26 +385,32 @@ describe('ReactPropTypes', () => {
it('should warn for missing required values', () => {
typeCheckFailRequiredValues(
- PropTypes.arrayOf(PropTypes.number).isRequired
+ PropTypes.arrayOf(PropTypes.number).isRequired,
);
});
it('should warn if called manually in development', () => {
spyOn(console, 'error');
+ expectWarningInDevelopment(PropTypes.arrayOf({foo: PropTypes.string}), {
+ foo: 'bar',
+ });
+ expectWarningInDevelopment(PropTypes.arrayOf(PropTypes.number), [
+ 1,
+ 2,
+ 'b',
+ ]);
+ expectWarningInDevelopment(PropTypes.arrayOf(PropTypes.number), {
+ '0': 'maybe-array',
+ length: 1,
+ });
expectWarningInDevelopment(
- PropTypes.arrayOf({ foo: PropTypes.string }),
- { foo: 'bar' }
+ PropTypes.arrayOf(PropTypes.number).isRequired,
+ null,
);
expectWarningInDevelopment(
- PropTypes.arrayOf(PropTypes.number),
- [1, 2, 'b']
+ PropTypes.arrayOf(PropTypes.number).isRequired,
+ undefined,
);
- expectWarningInDevelopment(
- PropTypes.arrayOf(PropTypes.number),
- {'0': 'maybe-array', length: 1}
- );
- expectWarningInDevelopment(PropTypes.arrayOf(PropTypes.number).isRequired, null);
- expectWarningInDevelopment(PropTypes.arrayOf(PropTypes.number).isRequired, undefined);
});
});
@@ -413,25 +436,25 @@ describe('ReactPropTypes', () => {
PropTypes.element,
[
,
],
'Invalid prop `testProp` of type `array` supplied to `testComponent`, ' +
- 'expected a single ReactElement.'
+ 'expected a single ReactElement.',
);
typeCheckFail(
PropTypes.element,
123,
'Invalid prop `testProp` of type `number` supplied to `testComponent`, ' +
- 'expected a single ReactElement.'
+ 'expected a single ReactElement.',
);
typeCheckFail(
PropTypes.element,
'foo',
'Invalid prop `testProp` of type `string` supplied to `testComponent`, ' +
- 'expected a single ReactElement.'
+ 'expected a single ReactElement.',
);
typeCheckFail(
PropTypes.element,
false,
'Invalid prop `testProp` of type `boolean` supplied to `testComponent`, ' +
- 'expected a single ReactElement.'
+ 'expected a single ReactElement.',
);
});
@@ -472,7 +495,6 @@ describe('ReactPropTypes', () => {
expectWarningInDevelopment(PropTypes.element.isRequired, null);
expectWarningInDevelopment(PropTypes.element.isRequired, undefined);
});
-
});
describe('Instance Types', () => {
@@ -487,43 +509,57 @@ describe('ReactPropTypes', () => {
PropTypes.instanceOf(Person),
false,
'Invalid prop `testProp` of type `Boolean` supplied to ' +
- '`testComponent`, expected instance of `' + personName + '`.'
+ '`testComponent`, expected instance of `' +
+ personName +
+ '`.',
);
typeCheckFail(
PropTypes.instanceOf(Person),
{},
'Invalid prop `testProp` of type `Object` supplied to ' +
- '`testComponent`, expected instance of `' + personName + '`.'
+ '`testComponent`, expected instance of `' +
+ personName +
+ '`.',
);
typeCheckFail(
PropTypes.instanceOf(Person),
'',
'Invalid prop `testProp` of type `String` supplied to ' +
- '`testComponent`, expected instance of `' + personName + '`.'
+ '`testComponent`, expected instance of `' +
+ personName +
+ '`.',
);
typeCheckFail(
PropTypes.instanceOf(Date),
{},
'Invalid prop `testProp` of type `Object` supplied to ' +
- '`testComponent`, expected instance of `' + dateName + '`.'
+ '`testComponent`, expected instance of `' +
+ dateName +
+ '`.',
);
typeCheckFail(
PropTypes.instanceOf(RegExp),
{},
'Invalid prop `testProp` of type `Object` supplied to ' +
- '`testComponent`, expected instance of `' + regExpName + '`.'
+ '`testComponent`, expected instance of `' +
+ regExpName +
+ '`.',
);
typeCheckFail(
PropTypes.instanceOf(Person),
new Cat(),
'Invalid prop `testProp` of type `Cat` supplied to ' +
- '`testComponent`, expected instance of `' + personName + '`.'
+ '`testComponent`, expected instance of `' +
+ personName +
+ '`.',
);
typeCheckFail(
PropTypes.instanceOf(Person),
Object.create(null),
'Invalid prop `testProp` of type `<
>` supplied to ' +
- '`testComponent`, expected instance of `' + personName + '`.'
+ '`testComponent`, expected instance of `' +
+ personName +
+ '`.',
);
});
@@ -553,9 +589,11 @@ describe('ReactPropTypes', () => {
expectWarningInDevelopment(PropTypes.instanceOf(Date), {});
expectWarningInDevelopment(PropTypes.instanceOf(Date), new Date());
expectWarningInDevelopment(PropTypes.instanceOf(Date).isRequired, {});
- expectWarningInDevelopment(PropTypes.instanceOf(Date).isRequired, new Date());
+ expectWarningInDevelopment(
+ PropTypes.instanceOf(Date).isRequired,
+ new Date(),
+ );
});
-
});
describe('React Component Types', () => {
@@ -594,18 +632,21 @@ describe('ReactPropTypes', () => {
// Object of renderable things
var frag = ReactFragment.create;
- typeCheckPass(PropTypes.node, frag({
- k0: 123,
- k1: 'Some string',
- k2: ,
- k3: frag({
- k30: ,
- k31: frag({k310: }),
- k32: 'Another string',
+ typeCheckPass(
+ PropTypes.node,
+ frag({
+ k0: 123,
+ k1: 'Some string',
+ k2: ,
+ k3: frag({
+ k30: ,
+ k31: frag({k310: }),
+ k32: 'Another string',
+ }),
+ k4: null,
+ k5: undefined,
}),
- k4: null,
- k5: undefined,
- }));
+ );
expectDev(console.error.calls.count()).toBe(0);
});
@@ -632,7 +673,10 @@ describe('ReactPropTypes', () => {
return {
next: function() {
var done = ++i > 2;
- return {value: done ? undefined : ['#' + i, ], done: done};
+ return {
+ value: done ? undefined : ['#' + i, ],
+ done: done,
+ };
},
};
},
@@ -663,45 +707,46 @@ describe('ReactPropTypes', () => {
expectWarningInDevelopment(PropTypes.node.isRequired, undefined);
expectWarningInDevelopment(PropTypes.node.isRequired, undefined);
});
-
});
describe('ObjectOf Type', () => {
it('should fail for invalid argument', () => {
typeCheckFail(
- PropTypes.objectOf({ foo: PropTypes.string }),
- { foo: 'bar' },
- 'Property `testProp` of component `testComponent` has invalid PropType notation inside objectOf.'
+ PropTypes.objectOf({foo: PropTypes.string}),
+ {foo: 'bar'},
+ 'Property `testProp` of component `testComponent` has invalid PropType notation inside objectOf.',
);
});
it('should support the objectOf propTypes', () => {
typeCheckPass(PropTypes.objectOf(PropTypes.number), {a: 1, b: 2, c: 3});
- typeCheckPass(
- PropTypes.objectOf(PropTypes.string),
- {a: 'a', b: 'b', c: 'c'}
- );
- typeCheckPass(
- PropTypes.objectOf(PropTypes.oneOf(['a', 'b'])),
- {a: 'a', b: 'b'}
- );
- typeCheckPass(
- PropTypes.objectOf(PropTypes.symbol),
- {a: Symbol(), b: Symbol(), c: Symbol()}
- );
+ typeCheckPass(PropTypes.objectOf(PropTypes.string), {
+ a: 'a',
+ b: 'b',
+ c: 'c',
+ });
+ typeCheckPass(PropTypes.objectOf(PropTypes.oneOf(['a', 'b'])), {
+ a: 'a',
+ b: 'b',
+ });
+ typeCheckPass(PropTypes.objectOf(PropTypes.symbol), {
+ a: Symbol(),
+ b: Symbol(),
+ c: Symbol(),
+ });
});
it('should support objectOf with complex types', () => {
typeCheckPass(
PropTypes.objectOf(PropTypes.shape({a: PropTypes.number.isRequired})),
- {a: {a: 1}, b: {a: 2}}
+ {a: {a: 1}, b: {a: 2}},
);
function Thing() {}
- typeCheckPass(
- PropTypes.objectOf(PropTypes.instanceOf(Thing)),
- {a: new Thing(), b: new Thing()}
- );
+ typeCheckPass(PropTypes.objectOf(PropTypes.instanceOf(Thing)), {
+ a: new Thing(),
+ b: new Thing(),
+ });
});
it('should warn with invalid items in the object', () => {
@@ -709,7 +754,7 @@ describe('ReactPropTypes', () => {
PropTypes.objectOf(PropTypes.number),
{a: 1, b: 2, c: 'b'},
'Invalid prop `testProp.c` of type `string` supplied to `testComponent`, ' +
- 'expected `number`.'
+ 'expected `number`.',
);
});
@@ -721,7 +766,9 @@ describe('ReactPropTypes', () => {
PropTypes.objectOf(PropTypes.instanceOf(Thing)),
{a: new Thing(), b: 'xyz'},
'Invalid prop `testProp.b` of type `String` supplied to ' +
- '`testComponent`, expected instance of `' + name + '`.'
+ '`testComponent`, expected instance of `' +
+ name +
+ '`.',
);
});
@@ -730,25 +777,25 @@ describe('ReactPropTypes', () => {
PropTypes.objectOf(PropTypes.number),
[1, 2],
'Invalid prop `testProp` of type `array` supplied to ' +
- '`testComponent`, expected an object.'
+ '`testComponent`, expected an object.',
);
typeCheckFail(
PropTypes.objectOf(PropTypes.number),
123,
'Invalid prop `testProp` of type `number` supplied to ' +
- '`testComponent`, expected an object.'
+ '`testComponent`, expected an object.',
);
typeCheckFail(
PropTypes.objectOf(PropTypes.number),
'string',
'Invalid prop `testProp` of type `string` supplied to ' +
- '`testComponent`, expected an object.'
+ '`testComponent`, expected an object.',
);
typeCheckFail(
PropTypes.objectOf(PropTypes.symbol),
Symbol(),
'Invalid prop `testProp` of type `symbol` supplied to ' +
- '`testComponent`, expected an object.'
+ '`testComponent`, expected an object.',
);
});
@@ -763,23 +810,26 @@ describe('ReactPropTypes', () => {
it('should warn for missing required values', () => {
typeCheckFailRequiredValues(
- PropTypes.objectOf(PropTypes.number).isRequired
+ PropTypes.objectOf(PropTypes.number).isRequired,
);
});
it('should warn if called manually in development', () => {
spyOn(console, 'error');
- expectWarningInDevelopment(
- PropTypes.objectOf({ foo: PropTypes.string }),
- { foo: 'bar' }
- );
- expectWarningInDevelopment(
- PropTypes.objectOf(PropTypes.number),
- {a: 1, b: 2, c: 'b'}
- );
+ expectWarningInDevelopment(PropTypes.objectOf({foo: PropTypes.string}), {
+ foo: 'bar',
+ });
+ expectWarningInDevelopment(PropTypes.objectOf(PropTypes.number), {
+ a: 1,
+ b: 2,
+ c: 'b',
+ });
expectWarningInDevelopment(PropTypes.objectOf(PropTypes.number), [1, 2]);
expectWarningInDevelopment(PropTypes.objectOf(PropTypes.number), null);
- expectWarningInDevelopment(PropTypes.objectOf(PropTypes.number), undefined);
+ expectWarningInDevelopment(
+ PropTypes.objectOf(PropTypes.number),
+ undefined,
+ );
});
});
@@ -790,8 +840,9 @@ describe('ReactPropTypes', () => {
PropTypes.oneOf('red', 'blue');
expectDev(console.error).toHaveBeenCalled();
- expectDev(console.error.calls.argsFor(0)[0])
- .toContain('Invalid argument supplied to oneOf, expected an instance of array.');
+ expectDev(console.error.calls.argsFor(0)[0]).toContain(
+ 'Invalid argument supplied to oneOf, expected an instance of array.',
+ );
typeCheckPass(PropTypes.oneOf('red', 'blue'), 'red');
});
@@ -801,25 +852,25 @@ describe('ReactPropTypes', () => {
PropTypes.oneOf(['red', 'blue']),
true,
'Invalid prop `testProp` of value `true` supplied to ' +
- '`testComponent`, expected one of ["red","blue"].'
+ '`testComponent`, expected one of ["red","blue"].',
);
typeCheckFail(
PropTypes.oneOf(['red', 'blue']),
[],
'Invalid prop `testProp` of value `` supplied to `testComponent`, ' +
- 'expected one of ["red","blue"].'
+ 'expected one of ["red","blue"].',
);
typeCheckFail(
PropTypes.oneOf(['red', 'blue']),
'',
'Invalid prop `testProp` of value `` supplied to `testComponent`, ' +
- 'expected one of ["red","blue"].'
+ 'expected one of ["red","blue"].',
);
typeCheckFail(
PropTypes.oneOf([0, 'false']),
false,
'Invalid prop `testProp` of value `false` supplied to ' +
- '`testComponent`, expected one of [0,"false"].'
+ '`testComponent`, expected one of [0,"false"].',
);
});
@@ -853,8 +904,9 @@ describe('ReactPropTypes', () => {
PropTypes.oneOfType(PropTypes.string, PropTypes.number);
expectDev(console.error).toHaveBeenCalled();
- expectDev(console.error.calls.argsFor(0)[0])
- .toContain('Invalid argument supplied to oneOfType, expected an instance of array.');
+ expectDev(console.error.calls.argsFor(0)[0]).toContain(
+ 'Invalid argument supplied to oneOfType, expected an instance of array.',
+ );
typeCheckPass(PropTypes.oneOf(PropTypes.string, PropTypes.number), []);
});
@@ -863,7 +915,7 @@ describe('ReactPropTypes', () => {
typeCheckFail(
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
[],
- 'Invalid prop `testProp` supplied to `testComponent`.'
+ 'Invalid prop `testProp` supplied to `testComponent`.',
);
var checker = PropTypes.oneOfType([
@@ -873,15 +925,12 @@ describe('ReactPropTypes', () => {
typeCheckFail(
checker,
{c: 1},
- 'Invalid prop `testProp` supplied to `testComponent`.'
+ 'Invalid prop `testProp` supplied to `testComponent`.',
);
});
it('should not warn if one of the types are valid', () => {
- var checker = PropTypes.oneOfType([
- PropTypes.string,
- PropTypes.number,
- ]);
+ var checker = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
typeCheckPass(checker, null);
typeCheckPass(checker, 'foo');
typeCheckPass(checker, 123);
@@ -896,16 +945,18 @@ describe('ReactPropTypes', () => {
it('should be implicitly optional and not warn without values', () => {
typeCheckPass(
- PropTypes.oneOfType([PropTypes.string, PropTypes.number]), null
+ PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
+ null,
);
typeCheckPass(
- PropTypes.oneOfType([PropTypes.string, PropTypes.number]), undefined
+ PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
+ undefined,
);
});
it('should warn for missing required values', () => {
typeCheckFailRequiredValues(
- PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired
+ PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
);
});
@@ -913,18 +964,17 @@ describe('ReactPropTypes', () => {
spyOn(console, 'error');
expectWarningInDevelopment(
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
- []
+ [],
);
expectWarningInDevelopment(
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
- null
+ null,
);
expectWarningInDevelopment(
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
- undefined
+ undefined,
);
});
-
});
describe('Shape Types', () => {
@@ -933,13 +983,13 @@ describe('ReactPropTypes', () => {
PropTypes.shape({}),
'some string',
'Invalid prop `testProp` of type `string` supplied to ' +
- '`testComponent`, expected `object`.'
+ '`testComponent`, expected `object`.',
);
typeCheckFail(
PropTypes.shape({}),
['array'],
'Invalid prop `testProp` of type `array` supplied to ' +
- '`testComponent`, expected `object`.'
+ '`testComponent`, expected `object`.',
);
});
@@ -966,7 +1016,7 @@ describe('ReactPropTypes', () => {
PropTypes.shape({key: PropTypes.number.isRequired}),
{},
'The prop `testProp.key` is marked as required in `testComponent`, ' +
- 'but its value is `undefined`.'
+ 'but its value is `undefined`.',
);
});
@@ -978,44 +1028,49 @@ describe('ReactPropTypes', () => {
}),
{},
'The prop `testProp.key` is marked as required in `testComponent`, ' +
- 'but its value is `undefined`.'
+ 'but its value is `undefined`.',
);
});
it('should warn for invalid key types', () => {
- typeCheckFail(PropTypes.shape({key: PropTypes.number}),
+ typeCheckFail(
+ PropTypes.shape({key: PropTypes.number}),
{key: 'abc'},
'Invalid prop `testProp.key` of type `string` supplied to `testComponent`, ' +
- 'expected `number`.'
+ 'expected `number`.',
);
});
it('should be implicitly optional and not warn without values', () => {
typeCheckPass(
- PropTypes.shape(PropTypes.shape({key: PropTypes.number})), null
+ PropTypes.shape(PropTypes.shape({key: PropTypes.number})),
+ null,
);
typeCheckPass(
- PropTypes.shape(PropTypes.shape({key: PropTypes.number})), undefined
+ PropTypes.shape(PropTypes.shape({key: PropTypes.number})),
+ undefined,
);
});
it('should warn for missing required values', () => {
typeCheckFailRequiredValues(
- PropTypes.shape({key: PropTypes.number}).isRequired
+ PropTypes.shape({key: PropTypes.number}).isRequired,
);
});
it('should warn if called manually in development', () => {
spyOn(console, 'error');
expectWarningInDevelopment(PropTypes.shape({}), 'some string');
- expectWarningInDevelopment(PropTypes.shape({ foo: PropTypes.number }), { foo: 42 });
+ expectWarningInDevelopment(PropTypes.shape({foo: PropTypes.number}), {
+ foo: 42,
+ });
expectWarningInDevelopment(
PropTypes.shape({key: PropTypes.number}).isRequired,
- null
+ null,
);
expectWarningInDevelopment(
PropTypes.shape({key: PropTypes.number}).isRequired,
- undefined
+ undefined,
);
expectWarningInDevelopment(PropTypes.element, );
});
@@ -1027,13 +1082,13 @@ describe('ReactPropTypes', () => {
PropTypes.symbol,
'hello',
'Invalid prop `testProp` of type `string` supplied to ' +
- '`testComponent`, expected `symbol`.'
+ '`testComponent`, expected `symbol`.',
);
typeCheckFail(
PropTypes.symbol,
- function() { },
+ function() {},
'Invalid prop `testProp` of type `function` supplied to ' +
- '`testComponent`, expected `symbol`.'
+ '`testComponent`, expected `symbol`.',
);
typeCheckFail(
PropTypes.symbol,
@@ -1041,7 +1096,7 @@ describe('ReactPropTypes', () => {
'@@toStringTag': 'Katana',
},
'Invalid prop `testProp` of type `object` supplied to ' +
- '`testComponent`, expected `symbol`.'
+ '`testComponent`, expected `symbol`.',
);
});
@@ -1090,15 +1145,15 @@ describe('ReactPropTypes', () => {
expect(spy.calls.argsFor(0)[1]).toBe('num');
});
- it('should have received the validator\'s return value', () => {
+ it("should have received the validator's return value", () => {
spyOn(console, 'error');
- var spy = jasmine.createSpy().and.callFake(
- function(props, propName, componentName) {
+ var spy = jasmine
+ .createSpy()
+ .and.callFake(function(props, propName, componentName) {
if (props[propName] !== 5) {
return new Error('num must be 5!');
}
- }
- );
+ });
Component = class extends React.Component {
static propTypes = {num: spy};
@@ -1111,33 +1166,31 @@ describe('ReactPropTypes', () => {
ReactDOM.render(, container);
expectDev(console.error.calls.count()).toBe(1);
expect(
- console.error.calls.argsFor(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 **)'
+ ' in Component (at **)',
);
});
- it('should not warn if the validator returned null',
- () => {
- spyOn(console, 'error');
- var spy = jasmine.createSpy().and.callFake(
- function(props, propName, componentName) {
- return null;
- }
- );
- Component = class extends React.Component {
- static propTypes = {num: spy};
+ it('should not warn if the validator returned null', () => {
+ spyOn(console, 'error');
+ var spy = jasmine
+ .createSpy()
+ .and.callFake(function(props, propName, componentName) {
+ return null;
+ });
+ Component = class extends React.Component {
+ static propTypes = {num: spy};
- render() {
- return ;
- }
- };
+ render() {
+ return ;
+ }
+ };
- var container = document.createElement('div');
- ReactDOM.render(, container);
- expectDev(console.error.calls.count()).toBe(0);
- }
- );
+ var container = document.createElement('div');
+ ReactDOM.render(, container);
+ expectDev(console.error.calls.count()).toBe(0);
+ });
});
});
diff --git a/src/isomorphic/classic/types/__tests__/ReactPropTypesProduction-test.js b/src/isomorphic/classic/types/__tests__/ReactPropTypesProduction-test.js
index 67842710e4..22d0ba1996 100644
--- a/src/isomorphic/classic/types/__tests__/ReactPropTypesProduction-test.js
+++ b/src/isomorphic/classic/types/__tests__/ReactPropTypesProduction-test.js
@@ -42,15 +42,8 @@ describe('ReactPropTypesProduction', function() {
function expectThrowsInProduction(declaration, value) {
var props = {testProp: value};
expect(() => {
- declaration(
- props,
- 'testProp',
- 'testComponent',
- 'prop'
- );
- }).toThrowError(
- 'Minified React error #144'
- );
+ declaration(props, 'testProp', 'testComponent', 'prop');
+ }).toThrowError('Minified React error #144');
}
describe('Primitive Types', function() {
@@ -96,20 +89,26 @@ describe('ReactPropTypesProduction', function() {
describe('ArrayOf Type', function() {
it('should be a no-op', function() {
+ expectThrowsInProduction(PropTypes.arrayOf({foo: PropTypes.string}), {
+ foo: 'bar',
+ });
+ expectThrowsInProduction(PropTypes.arrayOf(PropTypes.number), [
+ 1,
+ 2,
+ 'b',
+ ]);
+ expectThrowsInProduction(PropTypes.arrayOf(PropTypes.number), {
+ '0': 'maybe-array',
+ length: 1,
+ });
expectThrowsInProduction(
- PropTypes.arrayOf({ foo: PropTypes.string }),
- { foo: 'bar' }
+ PropTypes.arrayOf(PropTypes.number).isRequired,
+ null,
);
expectThrowsInProduction(
- PropTypes.arrayOf(PropTypes.number),
- [1, 2, 'b']
+ PropTypes.arrayOf(PropTypes.number).isRequired,
+ undefined,
);
- expectThrowsInProduction(
- PropTypes.arrayOf(PropTypes.number),
- {'0': 'maybe-array', length: 1}
- );
- expectThrowsInProduction(PropTypes.arrayOf(PropTypes.number).isRequired, null);
- expectThrowsInProduction(PropTypes.arrayOf(PropTypes.number).isRequired, undefined);
});
});
@@ -141,14 +140,14 @@ describe('ReactPropTypesProduction', function() {
describe('ObjectOf Type', function() {
it('should be a no-op', function() {
- expectThrowsInProduction(
- PropTypes.objectOf({ foo: PropTypes.string }),
- { foo: 'bar' }
- );
- expectThrowsInProduction(
- PropTypes.objectOf(PropTypes.number),
- {a: 1, b: 2, c: 'b'}
- );
+ expectThrowsInProduction(PropTypes.objectOf({foo: PropTypes.string}), {
+ foo: 'bar',
+ });
+ expectThrowsInProduction(PropTypes.objectOf(PropTypes.number), {
+ a: 1,
+ b: 2,
+ c: 'b',
+ });
expectThrowsInProduction(PropTypes.objectOf(PropTypes.number), [1, 2]);
expectThrowsInProduction(PropTypes.objectOf(PropTypes.number), null);
expectThrowsInProduction(PropTypes.objectOf(PropTypes.number), undefined);
@@ -168,19 +167,19 @@ describe('ReactPropTypesProduction', function() {
it('should be a no-op', function() {
expectThrowsInProduction(
PropTypes.oneOfType(PropTypes.string, PropTypes.number),
- 'red'
+ 'red',
);
expectThrowsInProduction(
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
- []
+ [],
);
expectThrowsInProduction(
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
- null
+ null,
);
expectThrowsInProduction(
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
- undefined
+ undefined,
);
});
});
@@ -190,11 +189,11 @@ describe('ReactPropTypesProduction', function() {
expectThrowsInProduction(PropTypes.shape({}), 'some string');
expectThrowsInProduction(
PropTypes.shape({key: PropTypes.number}).isRequired,
- null
+ null,
);
expectThrowsInProduction(
PropTypes.shape({key: PropTypes.number}).isRequired,
- undefined
+ undefined,
);
});
});
diff --git a/src/isomorphic/classic/types/checkPropTypes.js b/src/isomorphic/classic/types/checkPropTypes.js
index 5779168684..5168efd9c0 100644
--- a/src/isomorphic/classic/types/checkPropTypes.js
+++ b/src/isomorphic/classic/types/checkPropTypes.js
@@ -43,26 +43,33 @@ function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
invariant(
typeof typeSpecs[typeSpecName] === 'function',
'%s: %s type `%s` is invalid; it must be a function, usually from ' +
- 'React.PropTypes.',
+ 'React.PropTypes.',
componentName || 'React class',
location,
- typeSpecName
+ typeSpecName,
+ );
+ error = typeSpecs[typeSpecName](
+ values,
+ typeSpecName,
+ componentName,
+ location,
+ null,
+ ReactPropTypesSecret,
);
- error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
} catch (ex) {
error = ex;
}
warning(
!error || error instanceof Error,
'%s: type specification of %s `%s` is invalid; the type checker ' +
- 'function must return `null` or an `Error` but returned a %s. ' +
- 'You may have forgotten to pass an argument to the type checker ' +
- 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
- 'shape all require an argument).',
+ 'function must return `null` or an `Error` but returned a %s. ' +
+ 'You may have forgotten to pass an argument to the type checker ' +
+ 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
+ 'shape all require an argument).',
componentName || 'React class',
location,
typeSpecName,
- typeof error
+ typeof error,
);
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
// Only monitor this failure once because there tends to be a lot of the
diff --git a/src/isomorphic/hooks/ReactComponentTreeHook.js b/src/isomorphic/hooks/ReactComponentTreeHook.js
index 332c5cac8c..348a4c796b 100644
--- a/src/isomorphic/hooks/ReactComponentTreeHook.js
+++ b/src/isomorphic/hooks/ReactComponentTreeHook.js
@@ -21,24 +21,27 @@ var invariant = require('fbjs/lib/invariant');
var warning = require('fbjs/lib/warning');
var getComponentName = require('getComponentName');
-import type { ReactElement, Source } from 'ReactElementType';
-import type { DebugID } from 'ReactInstanceType';
-import type { Fiber } from 'ReactFiber';
+import type {ReactElement, Source} from 'ReactElementType';
+import type {DebugID} from 'ReactInstanceType';
+import type {Fiber} from 'ReactFiber';
function isNative(fn) {
// Based on isNative() from Lodash
var funcToString = Function.prototype.toString;
var hasOwnProperty = Object.prototype.hasOwnProperty;
- var reIsNative = RegExp('^' + funcToString
- // Take an example native function source for comparison
- .call(hasOwnProperty)
- // Strip regex characters so we can use it for regex
- .replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
- // Remove hasOwnProperty from the template to make it generic
- .replace(
- /hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,
- '$1.*?'
- ) + '$'
+ var reIsNative = RegExp(
+ '^' +
+ funcToString
+ // Take an example native function source for comparison
+ .call(hasOwnProperty)
+ // Strip regex characters so we can use it for regex
+ .replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
+ // Remove hasOwnProperty from the template to make it generic
+ .replace(
+ /hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,
+ '$1.*?',
+ ) +
+ '$',
);
try {
var source = funcToString.call(fn);
@@ -48,7 +51,7 @@ function isNative(fn) {
}
}
-var canUseCollections = (
+var canUseCollections =
// Array.from
typeof Array.from === 'function' &&
// Map
@@ -64,8 +67,7 @@ var canUseCollections = (
// Set.prototype.keys
Set.prototype != null &&
typeof Set.prototype.keys === 'function' &&
- isNative(Set.prototype.keys)
-);
+ isNative(Set.prototype.keys);
var setItem;
var getItem;
@@ -101,7 +103,6 @@ if (canUseCollections) {
getRootIDs = function() {
return Array.from(rootIDSet.keys());
};
-
} else {
var itemByKey = {};
var rootByKey = {};
@@ -179,10 +180,14 @@ function describeID(id: DebugID): string {
warning(
element,
'ReactComponentTreeHook: Missing React element for debugID %s when ' +
- 'building stack',
- id
+ 'building stack',
+ id,
+ );
+ return describeComponentFrame(
+ name || '',
+ element && element._source,
+ ownerName || '',
);
- return describeComponentFrame(name || '', element && element._source, ownerName || '');
}
var ReactComponentTreeHook = {
@@ -197,19 +202,19 @@ var ReactComponentTreeHook = {
invariant(
nextChild,
'Expected hook events to fire for the child ' +
- 'before its parent includes it in onSetChildren().'
+ 'before its parent includes it in onSetChildren().',
);
invariant(
nextChild.childIDs != null ||
- typeof nextChild.element !== 'object' ||
- nextChild.element == null,
+ typeof nextChild.element !== 'object' ||
+ nextChild.element == null,
'Expected onSetChildren() to fire for a container child ' +
- 'before its parent includes it in onSetChildren().'
+ 'before its parent includes it in onSetChildren().',
);
invariant(
nextChild.isMounted,
'Expected onMountComponent() to fire for the child ' +
- 'before its parent includes it in onSetChildren().'
+ 'before its parent includes it in onSetChildren().',
);
if (nextChild.parentID == null) {
nextChild.parentID = id;
@@ -220,15 +225,19 @@ var ReactComponentTreeHook = {
invariant(
nextChild.parentID === id,
'Expected onBeforeMountComponent() parent and onSetChildren() to ' +
- 'be consistent (%s has parents %s and %s).',
+ 'be consistent (%s has parents %s and %s).',
nextChildID,
nextChild.parentID,
- id
+ id,
);
}
},
- onBeforeMountComponent(id: DebugID, element: ReactElement, parentID: DebugID): void {
+ onBeforeMountComponent(
+ id: DebugID,
+ element: ReactElement,
+ parentID: DebugID,
+ ): void {
var item = {
element,
parentID,
@@ -313,19 +322,21 @@ var ReactComponentTreeHook = {
info += describeComponentFrame(
name,
topElement._source,
- owner && getComponentName(owner)
+ owner && getComponentName(owner),
);
}
var currentOwner = ReactCurrentOwner.current;
if (currentOwner) {
if (typeof currentOwner.tag === 'number') {
- const workInProgress = ((currentOwner : any) : Fiber);
+ const workInProgress = ((currentOwner: any): Fiber);
// Safe because if current owner exists, we are reconciling,
// and it is guaranteed to be the work-in-progress version.
info += getStackAddendumByWorkInProgressFiber(workInProgress);
} else if (typeof currentOwner._debugID === 'number') {
- info += ReactComponentTreeHook.getStackAddendumByID(currentOwner._debugID);
+ info += ReactComponentTreeHook.getStackAddendumByID(
+ currentOwner._debugID,
+ );
}
}
return info;
diff --git a/src/isomorphic/modern/class/ReactBaseClasses.js b/src/isomorphic/modern/class/ReactBaseClasses.js
index 3353461fe0..7397d8a49d 100644
--- a/src/isomorphic/modern/class/ReactBaseClasses.js
+++ b/src/isomorphic/modern/class/ReactBaseClasses.js
@@ -60,10 +60,10 @@ ReactComponent.prototype.isReactComponent = {};
ReactComponent.prototype.setState = function(partialState, callback) {
invariant(
typeof partialState === 'object' ||
- typeof partialState === 'function' ||
- partialState == null,
+ typeof partialState === 'function' ||
+ partialState == null,
'setState(...): takes an object of state variables to update or a ' +
- 'function which returns an object of state variables.'
+ 'function which returns an object of state variables.',
);
this.updater.enqueueSetState(this, partialState, callback, 'setState');
};
@@ -96,12 +96,12 @@ if (__DEV__) {
isMounted: [
'isMounted',
'Instead, make sure to clean up subscriptions and pending requests in ' +
- 'componentWillUnmount to prevent memory leaks.',
+ 'componentWillUnmount to prevent memory leaks.',
],
replaceState: [
'replaceState',
'Refactor your code to use setState instead (see ' +
- 'https://github.com/facebook/react/issues/3236).',
+ 'https://github.com/facebook/react/issues/3236).',
],
};
var defineDeprecationWarning = function(methodName, info) {
@@ -112,7 +112,7 @@ if (__DEV__) {
false,
'%s(...) is deprecated in plain JavaScript React classes. %s',
info[0],
- info[1]
+ info[1],
);
return undefined;
},
diff --git a/src/isomorphic/modern/class/ReactNoopUpdateQueue.js b/src/isomorphic/modern/class/ReactNoopUpdateQueue.js
index 41e8ee95e3..a66f30a6de 100644
--- a/src/isomorphic/modern/class/ReactNoopUpdateQueue.js
+++ b/src/isomorphic/modern/class/ReactNoopUpdateQueue.js
@@ -19,11 +19,12 @@ function warnNoop(publicInstance, callerName) {
warning(
false,
'%s(...): Can only update a mounted or mounting component. ' +
- 'This usually means you called %s() on an unmounted component. ' +
- 'This is a no-op.\n\nPlease check the code for the %s component.',
+ 'This usually means you called %s() on an unmounted component. ' +
+ 'This is a no-op.\n\nPlease check the code for the %s component.',
callerName,
callerName,
- constructor && (constructor.displayName || constructor.name) || 'ReactClass'
+ (constructor && (constructor.displayName || constructor.name)) ||
+ 'ReactClass',
);
}
}
@@ -32,7 +33,6 @@ function warnNoop(publicInstance, callerName) {
* This is the abstract API for an update queue.
*/
var ReactNoopUpdateQueue = {
-
/**
* Checks whether or not this composite component is mounted.
* @param {ReactClass} publicInstance The instance we want to test.
@@ -76,7 +76,12 @@ var ReactNoopUpdateQueue = {
* @param {?string} Name of the calling function in the public API.
* @internal
*/
- enqueueReplaceState: function(publicInstance, completeState, callback, callerName) {
+ enqueueReplaceState: function(
+ publicInstance,
+ completeState,
+ callback,
+ callerName,
+ ) {
warnNoop(publicInstance, 'replaceState');
},
@@ -92,7 +97,12 @@ var ReactNoopUpdateQueue = {
* @param {?string} Name of the calling function in the public API.
* @internal
*/
- enqueueSetState: function(publicInstance, partialState, callback, callerName) {
+ enqueueSetState: function(
+ publicInstance,
+ partialState,
+ callback,
+ callerName,
+ ) {
warnNoop(publicInstance, 'setState');
},
};
diff --git a/src/isomorphic/modern/class/__tests__/ReactClassEquivalence-test.js b/src/isomorphic/modern/class/__tests__/ReactClassEquivalence-test.js
index cae0e340bf..ea85c61667 100644
--- a/src/isomorphic/modern/class/__tests__/ReactClassEquivalence-test.js
+++ b/src/isomorphic/modern/class/__tests__/ReactClassEquivalence-test.js
@@ -26,7 +26,6 @@ describe('ReactClassEquivalence', () => {
var result2 = runJest('ReactES6Class-test.js');
compareResults(result1, result2);
});
-
});
function runJest(testFile) {
@@ -36,13 +35,13 @@ function runJest(testFile) {
var setupFile = path.resolve(
'scripts',
'jest',
- 'setupSpecEquivalenceReporter.js'
+ 'setupSpecEquivalenceReporter.js',
+ );
+ var result = spawnSync(
+ jestBin,
+ [testFile, '--setupTestFrameworkScriptFile', setupFile],
+ {cwd},
);
- var result = spawnSync(jestBin, [
- testFile,
- '--setupTestFrameworkScriptFile',
- setupFile,
- ], {cwd});
if (result.error) {
throw result.error;
@@ -51,12 +50,12 @@ function runJest(testFile) {
if (result.status !== 0) {
throw new Error(
'jest process exited with: ' +
- result.status +
- '\n' +
- 'stdout: ' +
- result.stdout.toString() +
- 'stderr: ' +
- result.stderr.toString()
+ result.status +
+ '\n' +
+ 'stdout: ' +
+ result.stdout.toString() +
+ 'stderr: ' +
+ result.stderr.toString(),
);
}
diff --git a/src/isomorphic/modern/class/__tests__/ReactES6Class-test.js b/src/isomorphic/modern/class/__tests__/ReactES6Class-test.js
index a0d80519ac..a6ec313d5c 100644
--- a/src/isomorphic/modern/class/__tests__/ReactES6Class-test.js
+++ b/src/isomorphic/modern/class/__tests__/ReactES6Class-test.js
@@ -15,7 +15,6 @@ var React;
var ReactDOM;
describe('ReactES6Class', () => {
-
var container;
var freeze = function(expectation) {
Object.freeze(expectation);
@@ -52,19 +51,19 @@ describe('ReactES6Class', () => {
}
it('preserves the name of the class for use in error messages', () => {
- class Foo extends React.Component { }
+ class Foo extends React.Component {}
expect(Foo.name).toBe('Foo');
});
it('throws if no render function is defined', () => {
spyOn(console, 'error');
- class Foo extends React.Component { }
+ class Foo extends React.Component {}
expect(() => ReactDOM.render(, container)).toThrow();
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`.'
+ 'instance: you may have forgotten to define `render`.',
);
});
@@ -174,7 +173,7 @@ describe('ReactES6Class', () => {
}
}
expect(() => test(, 'span', '')).toThrowError(
- 'Foo.state: must be set to an object or null'
+ 'Foo.state: must be set to an object or null',
);
});
});
@@ -203,10 +202,7 @@ describe('ReactES6Class', () => {
}
render() {
return (
-
+
);
}
}
@@ -225,12 +221,7 @@ describe('ReactES6Class', () => {
this.setState({bar: 'bar'});
}
render() {
- return (
-
- );
+ return ;
}
}
test(, 'DIV', 'foo');
@@ -295,12 +286,10 @@ describe('ReactES6Class', () => {
}
}
test(, 'SPAN', 'foo');
- expect(lifeCycles).toEqual([
- 'will-mount',
- 'did-mount',
- ]);
+ expect(lifeCycles).toEqual(['will-mount', 'did-mount']);
lifeCycles = []; // reset
test(, 'SPAN', 'bar');
+ // prettier-ignore
expect(lifeCycles).toEqual([
'receive-props', freeze({value: 'bar'}),
'should-update', freeze({value: 'bar'}), {},
@@ -309,9 +298,7 @@ describe('ReactES6Class', () => {
]);
lifeCycles = []; // reset
ReactDOM.unmountComponentAtNode(container);
- expect(lifeCycles).toEqual([
- 'will-unmount',
- ]);
+ expect(lifeCycles).toEqual(['will-unmount']);
});
it('warns when classic properties are defined on the instance, but does not invoke them.', () => {
@@ -341,16 +328,16 @@ describe('ReactES6Class', () => {
expect(getDefaultPropsWasCalled).toBe(false);
expect(console.error.calls.count()).toBe(4);
expect(console.error.calls.argsFor(0)[0]).toContain(
- 'getInitialState was defined on Foo, a plain JavaScript class.'
+ 'getInitialState was defined on Foo, a plain JavaScript class.',
);
expect(console.error.calls.argsFor(1)[0]).toContain(
- 'getDefaultProps was defined on Foo, a plain JavaScript class.'
+ 'getDefaultProps was defined on Foo, a plain JavaScript class.',
);
expect(console.error.calls.argsFor(2)[0]).toContain(
- 'propTypes was defined as an instance property on Foo.'
+ 'propTypes was defined as an instance property on Foo.',
);
expect(console.error.calls.argsFor(3)[0]).toContain(
- 'contextTypes was defined as an instance property on Foo.'
+ 'contextTypes was defined as an instance property on Foo.',
);
});
@@ -385,9 +372,9 @@ describe('ReactES6Class', () => {
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.'
+ '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.',
);
});
@@ -407,8 +394,8 @@ describe('ReactES6Class', () => {
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()?'
+ 'NamedComponent has a method called componentWillRecieveProps(). Did ' +
+ 'you mean componentWillReceiveProps()?',
);
});
@@ -419,10 +406,10 @@ describe('ReactES6Class', () => {
expect(() => instance.isMounted()).toThrow();
expect(console.error.calls.count()).toBe(2);
expect(console.error.calls.argsFor(0)[0]).toContain(
- 'replaceState(...) is deprecated in plain JavaScript React classes'
+ 'replaceState(...) is deprecated in plain JavaScript React classes',
);
expect(console.error.calls.argsFor(1)[0]).toContain(
- 'isMounted(...) is deprecated in plain JavaScript React classes'
+ 'isMounted(...) is deprecated in plain JavaScript React classes',
);
});
@@ -460,5 +447,4 @@ describe('ReactES6Class', () => {
var node = ReactDOM.findDOMNode(instance);
expect(node).toBe(container.firstChild);
});
-
});
diff --git a/src/isomorphic/modern/class/__tests__/ReactPureComponent-test.js b/src/isomorphic/modern/class/__tests__/ReactPureComponent-test.js
index 9407d17a0c..e7c03af27b 100644
--- a/src/isomorphic/modern/class/__tests__/ReactPureComponent-test.js
+++ b/src/isomorphic/modern/class/__tests__/ReactPureComponent-test.js
@@ -93,5 +93,4 @@ describe('ReactPureComponent', () => {
ReactDOM.render(, document.createElement('div'));
expect(renders).toBe(1);
});
-
});
diff --git a/src/isomorphic/modern/element/__tests__/ReactJSXElement-test.js b/src/isomorphic/modern/element/__tests__/ReactJSXElement-test.js
index 481fa625ba..8508cdf5a4 100644
--- a/src/isomorphic/modern/element/__tests__/ReactJSXElement-test.js
+++ b/src/isomorphic/modern/element/__tests__/ReactJSXElement-test.js
@@ -80,7 +80,7 @@ describe('ReactJSXElement', () => {
expect(element.type).toBe(Component);
expect(element.key).toBe('12');
expect(element.ref).toBe('34');
- var expectation = {foo:'56'};
+ var expectation = {foo: '56'};
Object.freeze(expectation);
expect(element.props).toEqual(expectation);
});
@@ -90,7 +90,7 @@ describe('ReactJSXElement', () => {
expect(element.type).toBe(Component);
expect(element.key).toBe('12');
expect(element.ref).toBe(null);
- var expectation = {foo:'56'};
+ var expectation = {foo: '56'};
Object.freeze(expectation);
expect(element.props).toEqual(expectation);
});
@@ -124,7 +124,7 @@ describe('ReactJSXElement', () => {
var element2 = React.cloneElement(
,
{},
- undefined
+ undefined,
);
expect(element2.props.children).toBe(undefined);
});
@@ -165,7 +165,7 @@ describe('ReactJSXElement', () => {
expect(React.isValidElement({})).toEqual(false);
expect(React.isValidElement('string')).toEqual(false);
expect(React.isValidElement(Component)).toEqual(false);
- expect(React.isValidElement({ type: 'div', props: {} })).toEqual(false);
+ expect(React.isValidElement({type: 'div', props: {}})).toEqual(false);
});
it('is indistinguishable from a plain object', () => {
@@ -178,10 +178,7 @@ describe('ReactJSXElement', () => {
Component.defaultProps = {fruit: 'persimmon'};
var container = document.createElement('div');
- var instance = ReactDOM.render(
- ,
- container
- );
+ var instance = ReactDOM.render(, container);
expect(instance.props.fruit).toBe('mango');
ReactDOM.render(, container);
@@ -199,9 +196,9 @@ describe('ReactJSXElement', () => {
var instance = ReactTestUtils.renderIntoDocument();
expect(instance.props.prop).toBe('testKey');
- var inst2 =
- ReactTestUtils.renderIntoDocument();
+ var inst2 = ReactTestUtils.renderIntoDocument(
+ ,
+ );
expect(inst2.props.prop).toBe(null);
});
-
});
diff --git a/src/isomorphic/modern/element/__tests__/ReactJSXElementValidator-test.js b/src/isomorphic/modern/element/__tests__/ReactJSXElementValidator-test.js
index 4dcc8c25cb..5074097dfa 100644
--- a/src/isomorphic/modern/element/__tests__/ReactJSXElementValidator-test.js
+++ b/src/isomorphic/modern/element/__tests__/ReactJSXElementValidator-test.js
@@ -55,7 +55,7 @@ describe('ReactJSXElementValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
- 'Each child in an array or iterator should have a unique "key" prop.'
+ 'Each child in an array or iterator should have a unique "key" prop.',
);
});
@@ -70,11 +70,7 @@ describe('ReactJSXElementValidator', () => {
class ComponentWrapper extends React.Component {
render() {
- return (
- , ]}
- />
- );
+ return , ]} />;
}
}
@@ -83,8 +79,8 @@ describe('ReactJSXElementValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Each child in an array or iterator should have a unique "key" prop.' +
- '\n\nCheck the render method of `InnerComponent`. ' +
- 'It was passed a child from ComponentWrapper. '
+ '\n\nCheck the render method of `InnerComponent`. ' +
+ 'It was passed a child from ComponentWrapper. ',
);
});
@@ -107,14 +103,16 @@ describe('ReactJSXElementValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
- 'Each child in an array or iterator should have a unique "key" prop.'
+ 'Each child in an array or iterator should have a unique "key" prop.',
);
});
it('does not warns for arrays of elements with keys', () => {
spyOn(console, 'error');
- void {[, ]};
+ void (
+ {[, ]}
+ );
expectDev(console.error.calls.count()).toBe(0);
});
@@ -200,10 +198,10 @@ describe('ReactJSXElementValidator', () => {
ReactTestUtils.renderIntoDocument();
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Failed prop type: ' +
- 'Invalid prop `color` of type `number` supplied to `MyComp`, ' +
- 'expected `string`.\n' +
- ' in MyComp (at **)\n' +
- ' in ParentComp (at **)'
+ 'Invalid prop `color` of type `number` supplied to `MyComp`, ' +
+ 'expected `string`.\n' +
+ ' in MyComp (at **)\n' +
+ ' in ParentComp (at **)',
);
});
@@ -236,11 +234,11 @@ describe('ReactJSXElementValidator', () => {
// If it doesn't, it means we're using information from the old element.
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Failed prop type: ' +
- 'Invalid prop `color` of type `number` supplied to `MyComp`, ' +
- 'expected `string`.\n' +
- ' in MyComp (at **)\n' +
- ' in MiddleComp (at **)\n' +
- ' in ParentComp (at **)'
+ 'Invalid prop `color` of type `number` supplied to `MyComp`, ' +
+ 'expected `string`.\n' +
+ ' in MyComp (at **)\n' +
+ ' in MiddleComp (at **)\n' +
+ ' in ParentComp (at **)',
);
});
@@ -258,28 +256,28 @@ describe('ReactJSXElementValidator', () => {
expectDev(console.error.calls.count()).toBe(4);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: React.createElement: type is invalid -- expected a string ' +
- '(for built-in components) or a class/function (for composite ' +
- 'components) but got: undefined. You likely forgot to export your ' +
- 'component from the file it\'s defined in.' +
- '\n\nCheck your code at **.'
+ '(for built-in components) or a class/function (for composite ' +
+ 'components) but got: undefined. You likely forgot to export your ' +
+ "component from the file it's defined in." +
+ '\n\nCheck your code at **.',
);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
'Warning: React.createElement: type is invalid -- expected a string ' +
- '(for built-in components) or a class/function (for composite ' +
- 'components) but got: null.' +
- '\n\nCheck your code at **.'
+ '(for built-in components) or a class/function (for composite ' +
+ 'components) but got: null.' +
+ '\n\nCheck your code at **.',
);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(2)[0])).toBe(
'Warning: React.createElement: type is invalid -- expected a string ' +
- '(for built-in components) or a class/function (for composite ' +
- 'components) but got: boolean.' +
- '\n\nCheck your code at **.'
+ '(for built-in components) or a class/function (for composite ' +
+ 'components) but got: boolean.' +
+ '\n\nCheck your code at **.',
);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(3)[0])).toBe(
'Warning: React.createElement: type is invalid -- expected a string ' +
- '(for built-in components) or a class/function (for composite ' +
- 'components) but got: number.' +
- '\n\nCheck your code at **.'
+ '(for built-in components) or a class/function (for composite ' +
+ 'components) but got: number.' +
+ '\n\nCheck your code at **.',
);
void ;
expectDev(console.error.calls.count()).toBe(4);
@@ -295,8 +293,8 @@ describe('ReactJSXElementValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Failed prop type: The prop `prop` is marked as required in ' +
- '`RequiredPropComponent`, but its value is `null`.\n' +
- ' in RequiredPropComponent (at **)'
+ '`RequiredPropComponent`, but its value is `null`.\n' +
+ ' in RequiredPropComponent (at **)',
);
});
@@ -308,8 +306,8 @@ describe('ReactJSXElementValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Failed prop type: The prop `prop` is marked as required in ' +
- '`RequiredPropComponent`, but its value is `null`.\n' +
- ' in RequiredPropComponent (at **)'
+ '`RequiredPropComponent`, but its value is `null`.\n' +
+ ' in RequiredPropComponent (at **)',
);
});
@@ -322,16 +320,16 @@ describe('ReactJSXElementValidator', () => {
expectDev(console.error.calls.count()).toBe(2);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Failed prop type: ' +
- 'The prop `prop` is marked as required in `RequiredPropComponent`, but ' +
- 'its value is `undefined`.\n' +
- ' in RequiredPropComponent (at **)'
+ 'The prop `prop` is marked as required in `RequiredPropComponent`, but ' +
+ 'its value is `undefined`.\n' +
+ ' in RequiredPropComponent (at **)',
);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
'Warning: Failed prop type: ' +
- 'Invalid prop `prop` of type `number` supplied to ' +
- '`RequiredPropComponent`, expected `string`.\n' +
- ' in RequiredPropComponent (at **)'
+ 'Invalid prop `prop` of type `number` supplied to ' +
+ '`RequiredPropComponent`, expected `string`.\n' +
+ ' in RequiredPropComponent (at **)',
);
ReactTestUtils.renderIntoDocument();
@@ -358,7 +356,7 @@ describe('ReactJSXElementValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'NullPropTypeComponent: prop type `prop` is invalid; it must be a ' +
- 'function, usually from React.PropTypes.'
+ 'function, usually from React.PropTypes.',
);
});
@@ -376,7 +374,7 @@ describe('ReactJSXElementValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'NullContextTypeComponent: context type `prop` is invalid; it must ' +
- 'be a function, usually from React.PropTypes.'
+ 'be a function, usually from React.PropTypes.',
);
});
@@ -394,8 +392,7 @@ describe('ReactJSXElementValidator', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'getDefaultProps is only used on classic React.createClass definitions.' +
- ' Use a static property named `defaultProps` instead.'
+ ' Use a static property named `defaultProps` instead.',
);
});
-
});
diff --git a/src/renderers/__tests__/EventPluginHub-test.js b/src/renderers/__tests__/EventPluginHub-test.js
index 54cd8498f1..a94ae72bc3 100644
--- a/src/renderers/__tests__/EventPluginHub-test.js
+++ b/src/renderers/__tests__/EventPluginHub-test.js
@@ -25,22 +25,19 @@ describe('EventPluginHub', () => {
it('should prevent non-function listeners, at dispatch', () => {
var node = ReactTestUtils.renderIntoDocument(
-
+ ,
);
expect(function() {
ReactTestUtils.SimulateNative.click(node);
}).toThrowError(
- 'Expected onClick listener to be a function, instead got type string'
+ 'Expected onClick listener to be a function, instead got type string',
);
});
it('should not prevent null listeners, at dispatch', () => {
- var node = ReactTestUtils.renderIntoDocument(
-
- );
+ var node = ReactTestUtils.renderIntoDocument();
expect(function() {
ReactTestUtils.SimulateNative.click(node);
}).not.toThrow();
});
-
});
diff --git a/src/renderers/__tests__/ReactChildReconciler-test.js b/src/renderers/__tests__/ReactChildReconciler-test.js
index 5ea955eaa5..f6761ef181 100644
--- a/src/renderers/__tests__/ReactChildReconciler-test.js
+++ b/src/renderers/__tests__/ReactChildReconciler-test.js
@@ -60,7 +60,7 @@ describe('ReactChildReconciler', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
- 'Child keys must be unique; when two children share a key, only the first child will be used.'
+ 'Child keys must be unique; when two children share a key, only the first child will be used.',
);
});
@@ -88,14 +88,16 @@ describe('ReactChildReconciler', () => {
ReactTestUtils.renderIntoDocument();
expectDev(console.error.calls.count()).toBe(1);
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toContain(
+ expectDev(
+ normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]),
+ ).toContain(
'Encountered two children with the same key, `1`. ' +
- 'Child keys must be unique; when two children share a key, ' +
- 'only the first child will be used.\n' +
- ' in div (at **)\n' +
- ' in Component (at **)\n' +
- ' in Parent (at **)\n' +
- ' in GrandParent (at **)'
+ 'Child keys must be unique; when two children share a key, ' +
+ 'only the first child will be used.\n' +
+ ' in div (at **)\n' +
+ ' in Component (at **)\n' +
+ ' in Parent (at **)\n' +
+ ' in GrandParent (at **)',
);
});
@@ -112,7 +114,7 @@ describe('ReactChildReconciler', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
- 'Child keys must be unique; when two children share a key, only the first child will be used.'
+ 'Child keys must be unique; when two children share a key, only the first child will be used.',
);
});
@@ -140,14 +142,16 @@ describe('ReactChildReconciler', () => {
ReactTestUtils.renderIntoDocument();
expectDev(console.error.calls.count()).toBe(1);
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toContain(
+ expectDev(
+ normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]),
+ ).toContain(
'Encountered two children with the same key, `1`. ' +
- 'Child keys must be unique; when two children share a key, ' +
- 'only the first child will be used.\n' +
- ' in div (at **)\n' +
- ' in Component (at **)\n' +
- ' in Parent (at **)\n' +
- ' in GrandParent (at **)'
+ 'Child keys must be unique; when two children share a key, ' +
+ 'only the first child will be used.\n' +
+ ' in div (at **)\n' +
+ ' in Component (at **)\n' +
+ ' in Parent (at **)\n' +
+ ' in GrandParent (at **)',
);
});
});
diff --git a/src/renderers/__tests__/ReactComponent-test.js b/src/renderers/__tests__/ReactComponent-test.js
index 91598c4ab0..b909c8ab10 100644
--- a/src/renderers/__tests__/ReactComponent-test.js
+++ b/src/renderers/__tests__/ReactComponent-test.js
@@ -29,15 +29,11 @@ describe('ReactComponent', () => {
// jQuery objects are basically arrays; people often pass them in by mistake
expect(function() {
ReactDOM.render(, [container]);
- }).toThrowError(
- /Target container is not a DOM element./
- );
+ }).toThrowError(/Target container is not a DOM element./);
expect(function() {
ReactDOM.render(, null);
- }).toThrowError(
- /Target container is not a DOM element./
- );
+ }).toThrowError(/Target container is not a DOM element./);
});
it('should throw when supplying a ref outside of render method', () => {
@@ -59,7 +55,7 @@ describe('ReactComponent', () => {
-
+ ,
);
}).toThrowError(/Cannot assign to read only property.*/);
});
@@ -84,7 +80,7 @@ describe('ReactComponent', () => {
-
+ ,
);
}).toThrowError(/Cannot assign to read only property.*/);
});
@@ -157,9 +153,9 @@ describe('ReactComponent', () => {
class Component extends React.Component {
render() {
- var inner = this.innerRef = c} />;
+ var inner = this.innerRef = c} />;
var outer = (
- this.outerRef = c}>
+ this.outerRef = c}>
{inner}
);
@@ -194,16 +190,16 @@ describe('ReactComponent', () => {
getInner = () => {
// (With old-style refs, it's impossible to get a ref to this div
// because Wrapper is the current owner when this function is called.)
- return this.innerRef = c} />;
+ return
this.innerRef = c} />;
};
render() {
return (
this.wrapperRef = c}
+ ref={c => this.wrapperRef = c}
getContent={this.getInner}
- />
+ />
);
}
@@ -245,12 +241,18 @@ describe('ReactComponent', () => {
render() {
return (
- {
- log.push(`ref 1 got ${c ? `instance ${c.props.id}` : 'null'}`);
- }} />
- {
- log.push(`ref 2 got ${c ? `instance ${c.props.id}` : 'null'}`);
- }} />
+ {
+ log.push(`ref 1 got ${c ? `instance ${c.props.id}` : 'null'}`);
+ }}
+ />
+ {
+ log.push(`ref 2 got ${c ? `instance ${c.props.id}` : 'null'}`);
+ }}
+ />
);
}
@@ -280,39 +282,41 @@ describe('ReactComponent', () => {
/* eslint-disable indent */
expect(log).toEqual([
'start mount',
- 'inner 1 render',
- 'inner 2 render',
- 'inner 1 componentDidMount',
- 'ref 1 got instance 1',
- 'inner 2 componentDidMount',
- 'ref 2 got instance 2',
- 'outer componentDidMount',
+ 'inner 1 render',
+ 'inner 2 render',
+ 'inner 1 componentDidMount',
+ 'ref 1 got instance 1',
+ 'inner 2 componentDidMount',
+ 'ref 2 got instance 2',
+ 'outer componentDidMount',
'start update',
- // Previous (equivalent) refs get cleared
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Fiber renders first, resets refs later
- 'inner 1 render',
- 'inner 2 render',
- 'ref 1 got null',
- 'ref 2 got null',
- ] : [
- // Stack resets refs before rendering
- 'ref 1 got null',
- 'inner 1 render',
- 'ref 2 got null',
- 'inner 2 render',
- ]),
- 'inner 1 componentDidUpdate',
- 'ref 1 got instance 1',
- 'inner 2 componentDidUpdate',
- 'ref 2 got instance 2',
- 'outer componentDidUpdate',
+ // Previous (equivalent) refs get cleared
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Fiber renders first, resets refs later
+ 'inner 1 render',
+ 'inner 2 render',
+ 'ref 1 got null',
+ 'ref 2 got null',
+ ]
+ : [
+ // Stack resets refs before rendering
+ 'ref 1 got null',
+ 'inner 1 render',
+ 'ref 2 got null',
+ 'inner 2 render',
+ ]),
+ 'inner 1 componentDidUpdate',
+ 'ref 1 got instance 1',
+ 'inner 2 componentDidUpdate',
+ 'ref 2 got instance 2',
+ 'outer componentDidUpdate',
'start unmount',
- 'outer componentWillUnmount',
- 'ref 1 got null',
- 'inner 1 componentWillUnmount',
- 'ref 2 got null',
- 'inner 2 componentWillUnmount',
+ 'outer componentWillUnmount',
+ 'ref 1 got null',
+ 'inner 1 componentWillUnmount',
+ 'ref 2 got null',
+ 'inner 2 componentWillUnmount',
]);
/* eslint-enable indent */
});
@@ -334,15 +338,15 @@ describe('ReactComponent', () => {
var X = undefined;
expect(() => ReactTestUtils.renderIntoDocument()).toThrowError(
'Element type is invalid: expected a string (for built-in components) ' +
- 'or a class/function (for composite components) but got: undefined. ' +
- 'You likely forgot to export your component from the file it\'s ' +
- 'defined in.'
+ 'or a class/function (for composite components) but got: undefined. ' +
+ "You likely forgot to export your component from the file it's " +
+ 'defined in.',
);
var Y = null;
expect(() => ReactTestUtils.renderIntoDocument()).toThrowError(
'Element type is invalid: expected a string (for built-in components) ' +
- 'or a class/function (for composite components) but got: null.'
+ 'or a class/function (for composite components) but got: null.',
);
// One warning for each element creation
@@ -368,13 +372,12 @@ describe('ReactComponent', () => {
expect(() => ReactTestUtils.renderIntoDocument()).toThrowError(
'Element type is invalid: expected a string (for built-in components) ' +
- 'or a class/function (for composite components) but got: undefined. ' +
- 'You likely forgot to export your component from the file it\'s ' +
- 'defined in.\n\nCheck the render method of `Bar`.'
+ 'or a class/function (for composite components) but got: undefined. ' +
+ "You likely forgot to export your component from the file it's " +
+ 'defined in.\n\nCheck the render method of `Bar`.',
);
// One warning for each element creation
expectDev(console.error.calls.count()).toBe(1);
});
-
});
diff --git a/src/renderers/__tests__/ReactComponentLifeCycle-test.js b/src/renderers/__tests__/ReactComponentLifeCycle-test.js
index 9d0d317d22..e65acdfbd1 100644
--- a/src/renderers/__tests__/ReactComponentLifeCycle-test.js
+++ b/src/renderers/__tests__/ReactComponentLifeCycle-test.js
@@ -19,7 +19,6 @@ var clone = function(o) {
return JSON.parse(JSON.stringify(o));
};
-
var GET_INIT_STATE_RETURN_VAL = {
hasWillMountCompleted: false,
hasRenderCompleted: false,
@@ -70,16 +69,13 @@ type ComponentLifeCycle =
* Mounted components have a DOM node representation and are capable of
* receiving new props.
*/
- 'MOUNTED' |
- /**
+ | 'MOUNTED' /**
* Unmounted components are inactive and cannot receive new props.
*/
- 'UNMOUNTED';
+ | 'UNMOUNTED';
function getLifeCycleState(instance): ComponentLifeCycle {
- return instance.updater.isMounted(instance) ?
- 'MOUNTED' :
- 'UNMOUNTED';
+ return instance.updater.isMounted(instance) ? 'MOUNTED' : 'UNMOUNTED';
}
/**
@@ -104,9 +100,7 @@ describe('ReactComponentLifeCycle', () => {
state = {};
render() {
- return (
-
- );
+ return ;
}
}
@@ -152,11 +146,9 @@ describe('ReactComponentLifeCycle', () => {
render() {
return (
- {
- this.state.showHasOnDOMReadyComponent ?
-
:
-
- }
+
+ {this.state.showHasOnDOMReadyComponent ?
:
}
+
);
}
}
@@ -178,9 +170,7 @@ describe('ReactComponentLifeCycle', () => {
}
render() {
- return (
-
- );
+ return ;
}
}
@@ -197,9 +187,7 @@ describe('ReactComponentLifeCycle', () => {
}
render() {
- return (
-
- );
+ return ;
}
}
@@ -221,9 +209,7 @@ describe('ReactComponentLifeCycle', () => {
}
render() {
- return (
-
- );
+ return ;
}
}
@@ -231,9 +217,9 @@ describe('ReactComponentLifeCycle', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(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.\n\nPlease check the code for the ' +
- 'StatefulComponent component.'
+ 'mounting component. This usually means you called setState() on an ' +
+ 'unmounted component. This is a no-op.\n\nPlease check the code for the ' +
+ 'StatefulComponent component.',
);
});
@@ -259,7 +245,7 @@ describe('ReactComponentLifeCycle', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
- 'Component is accessing isMounted inside its render()'
+ 'Component is accessing isMounted inside its render()',
);
});
@@ -285,7 +271,7 @@ describe('ReactComponentLifeCycle', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
- 'Component is accessing isMounted inside its render()'
+ 'Component is accessing isMounted inside its render()',
);
});
@@ -326,14 +312,13 @@ describe('ReactComponentLifeCycle', () => {
ReactTestUtils.renderIntoDocument();
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
- 'Component is accessing findDOMNode inside its render()'
+ 'Component is accessing findDOMNode inside its render()',
);
});
it('should carry through each of the phases of setup', () => {
spyOn(console, 'error');
-
class LifeCycleComponent extends React.Component {
constructor(props, context) {
super(props, context);
@@ -345,22 +330,21 @@ describe('ReactComponentLifeCycle', () => {
hasWillUnmountCompleted: false,
};
this._testJournal.returnedFromGetInitialState = clone(initState);
- this._testJournal.lifeCycleAtStartOfGetInitialState =
- getLifeCycleState(this);
+ this._testJournal.lifeCycleAtStartOfGetInitialState = getLifeCycleState(
+ this,
+ );
this.state = initState;
}
componentWillMount() {
this._testJournal.stateAtStartOfWillMount = clone(this.state);
- this._testJournal.lifeCycleAtStartOfWillMount =
- getLifeCycleState(this);
+ this._testJournal.lifeCycleAtStartOfWillMount = getLifeCycleState(this);
this.state.hasWillMountCompleted = true;
}
componentDidMount() {
this._testJournal.stateAtStartOfDidMount = clone(this.state);
- this._testJournal.lifeCycleAtStartOfDidMount =
- getLifeCycleState(this);
+ this._testJournal.lifeCycleAtStartOfDidMount = getLifeCycleState(this);
this.setState({hasDidMountCompleted: true});
}
@@ -384,8 +368,9 @@ describe('ReactComponentLifeCycle', () => {
componentWillUnmount() {
this._testJournal.stateAtStartOfWillUnmount = clone(this.state);
- this._testJournal.lifeCycleAtStartOfWillUnmount =
- getLifeCycleState(this);
+ this._testJournal.lifeCycleAtStartOfWillUnmount = getLifeCycleState(
+ this,
+ );
this.state.hasWillUnmountCompleted = true;
}
}
@@ -398,31 +383,29 @@ describe('ReactComponentLifeCycle', () => {
// getInitialState
expect(instance._testJournal.returnedFromGetInitialState).toEqual(
- GET_INIT_STATE_RETURN_VAL
+ GET_INIT_STATE_RETURN_VAL,
+ );
+ expect(instance._testJournal.lifeCycleAtStartOfGetInitialState).toBe(
+ 'UNMOUNTED',
);
- expect(instance._testJournal.lifeCycleAtStartOfGetInitialState)
- .toBe('UNMOUNTED');
// componentWillMount
expect(instance._testJournal.stateAtStartOfWillMount).toEqual(
- instance._testJournal.returnedFromGetInitialState
+ instance._testJournal.returnedFromGetInitialState,
);
- expect(instance._testJournal.lifeCycleAtStartOfWillMount)
- .toBe('UNMOUNTED');
+ expect(instance._testJournal.lifeCycleAtStartOfWillMount).toBe('UNMOUNTED');
// componentDidMount
- expect(instance._testJournal.stateAtStartOfDidMount)
- .toEqual(DID_MOUNT_STATE);
- expect(instance._testJournal.lifeCycleAtStartOfDidMount).toBe(
- 'MOUNTED'
+ expect(instance._testJournal.stateAtStartOfDidMount).toEqual(
+ DID_MOUNT_STATE,
);
+ expect(instance._testJournal.lifeCycleAtStartOfDidMount).toBe('MOUNTED');
// initial render
- expect(instance._testJournal.stateInInitialRender)
- .toEqual(INIT_RENDER_STATE);
- expect(instance._testJournal.lifeCycleInInitialRender).toBe(
- 'UNMOUNTED'
+ expect(instance._testJournal.stateInInitialRender).toEqual(
+ INIT_RENDER_STATE,
);
+ expect(instance._testJournal.lifeCycleInInitialRender).toBe('UNMOUNTED');
expect(getLifeCycleState(instance)).toBe('MOUNTED');
@@ -430,22 +413,18 @@ describe('ReactComponentLifeCycle', () => {
instance.forceUpdate();
// render 2nd time
- expect(instance._testJournal.stateInLaterRender)
- .toEqual(NEXT_RENDER_STATE);
- expect(instance._testJournal.lifeCycleInLaterRender).toBe(
- 'MOUNTED'
- );
+ expect(instance._testJournal.stateInLaterRender).toEqual(NEXT_RENDER_STATE);
+ expect(instance._testJournal.lifeCycleInLaterRender).toBe('MOUNTED');
expect(getLifeCycleState(instance)).toBe('MOUNTED');
ReactDOM.unmountComponentAtNode(container);
- expect(instance._testJournal.stateAtStartOfWillUnmount)
- .toEqual(WILL_UNMOUNT_STATE);
- // componentWillUnmount called right before unmount.
- expect(instance._testJournal.lifeCycleAtStartOfWillUnmount).toBe(
- 'MOUNTED'
+ expect(instance._testJournal.stateAtStartOfWillUnmount).toEqual(
+ WILL_UNMOUNT_STATE,
);
+ // componentWillUnmount called right before unmount.
+ expect(instance._testJournal.lifeCycleAtStartOfWillUnmount).toBe('MOUNTED');
// But the current lifecycle of the component is unmounted.
expect(getLifeCycleState(instance)).toBe('UNMOUNTED');
@@ -453,7 +432,7 @@ describe('ReactComponentLifeCycle', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
- 'LifeCycleComponent is accessing isMounted inside its render() function'
+ 'LifeCycleComponent is accessing isMounted inside its render() function',
);
});
@@ -482,9 +461,7 @@ describe('ReactComponentLifeCycle', () => {
class Component extends React.Component {
render() {
return (
- {this.props.tooltipText}}>
+
{this.props.tooltipText} }>
{this.props.text}
);
@@ -492,17 +469,11 @@ describe('ReactComponentLifeCycle', () => {
}
var container = document.createElement('div');
- ReactDOM.render(
- ,
- container
- );
+ ReactDOM.render(, container);
// Since `instance` is a root component, we can set its props. This also
// makes Tooltip rerender the tooltip component, which shouldn't throw.
- ReactDOM.render(
- ,
- container
- );
+ ReactDOM.render(, container);
});
it('should allow state updates in componentDidMount', () => {
@@ -519,15 +490,16 @@ describe('ReactComponentLifeCycle', () => {
}
render() {
- return ();
+ return ;
}
}
- var instance =
+ var instance = (
;
+ />
+ );
instance = ReactTestUtils.renderIntoDocument(instance);
expect(instance.state.stateField).toBe('goodbye');
});
@@ -566,7 +538,6 @@ describe('ReactComponentLifeCycle', () => {
componentWillUnmount: logger('inner componentWillUnmount'),
});
-
var container = document.createElement('div');
log = [];
ReactDOM.render(, container);
@@ -634,8 +605,8 @@ describe('ReactComponentLifeCycle', () => {
};
const div = document.createElement('div');
- ReactDOM.render( c && log.push('ref')} />, div);
- ReactDOM.render( c && log.push('ref')} />, div);
+ ReactDOM.render( c && log.push('ref')} />, div);
+ ReactDOM.render( c && log.push('ref')} />, div);
expect(log).toEqual([
'will mount',
diff --git a/src/renderers/__tests__/ReactComponentTreeHook-test.js b/src/renderers/__tests__/ReactComponentTreeHook-test.js
index da91ab2627..0decdcd72f 100644
--- a/src/renderers/__tests__/ReactComponentTreeHook-test.js
+++ b/src/renderers/__tests__/ReactComponentTreeHook-test.js
@@ -44,20 +44,12 @@ describe('ReactComponentTreeHook', () => {
var Anon = React.createClass({displayName: null, render: () => null});
var Orange = React.createClass({render: () => null});
- expectDev(getAddendum()).toBe(
- ''
- );
- expectDev(getAddendum()).toBe(
- '\n in div (at **)'
- );
- expectDev(getAddendum()).toBe(
- '\n in Unknown (at **)'
- );
- expectDev(getAddendum()).toBe(
- '\n in Orange (at **)'
- );
+ expectDev(getAddendum()).toBe('');
+ expectDev(getAddendum()).toBe('\n in div (at **)');
+ expectDev(getAddendum()).toBe('\n in Unknown (at **)');
+ expectDev(getAddendum()).toBe('\n in Orange (at **)');
expectDev(getAddendum(React.createElement(Orange))).toBe(
- '\n in Orange'
+ '\n in Orange',
);
var renders = 0;
@@ -78,23 +70,23 @@ describe('ReactComponentTreeHook', () => {
render() {
expectDev(getAddendum()).toBe(
'\n in S (at **)' +
- '\n in div (at **)' +
- '\n in R (created by Q)' +
- '\n in Q (at **)'
+ '\n in div (at **)' +
+ '\n in R (created by Q)' +
+ '\n in Q (at **)',
);
expectDev(getAddendum()).toBe(
'\n in span (at **)' +
- '\n in S (at **)' +
- '\n in div (at **)' +
- '\n in R (created by Q)' +
- '\n in Q (at **)'
+ '\n in S (at **)' +
+ '\n in div (at **)' +
+ '\n in R (created by Q)' +
+ '\n in Q (at **)',
);
expectDev(getAddendum(React.createElement('span'))).toBe(
'\n in span (created by S)' +
- '\n in S (at **)' +
- '\n in div (at **)' +
- '\n in R (created by Q)' +
- '\n in Q (at **)'
+ '\n in S (at **)' +
+ '\n in div (at **)' +
+ '\n in R (created by Q)' +
+ '\n in Q (at **)',
);
renders++;
return null;
@@ -104,9 +96,7 @@ describe('ReactComponentTreeHook', () => {
expectDev(renders).toBe(2);
// Make sure owner is fetched for the top element too.
- expectDev(getAddendum(rOwnedByQ)).toBe(
- '\n in R (created by Q)'
- );
+ expectDev(getAddendum(rOwnedByQ)).toBe('\n in R (created by Q)');
});
// These are features and regression tests that only affect
@@ -126,7 +116,7 @@ describe('ReactComponentTreeHook', () => {
var q = ReactDOM.render(, document.createElement('div'));
expectDev(getAddendum(ReactInstanceMap.get(q)._debugID)).toBe(
- '\n in Q (at **)'
+ '\n in Q (at **)',
);
spyOn(console, 'error');
@@ -134,7 +124,7 @@ describe('ReactComponentTreeHook', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: ReactComponentTreeHook: Missing React element for ' +
- 'debugID -17 when building stack'
+ 'debugID -17 when building stack',
);
});
@@ -278,16 +268,20 @@ describe('ReactComponentTreeHook', () => {
var element =
;
var tree = {
displayName: 'div',
- children: [{
- displayName: 'Bar',
- children: [],
- }, {
- displayName: 'Baz',
- children: [],
- }, {
- displayName: 'Unknown',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ {
+ displayName: 'Baz',
+ children: [],
+ },
+ {
+ displayName: 'Unknown',
+ children: [],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -315,17 +309,21 @@ describe('ReactComponentTreeHook', () => {
var tree = {
displayName: 'div',
element,
- children: [{
- displayName: 'Bar',
- children: [],
- }, {
- displayName: 'Baz',
- children: [],
- }, {
- // Note: Ideally fallback name should be consistent (e.g. "Unknown")
- displayName: 'ReactComponent',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ {
+ displayName: 'Baz',
+ children: [],
+ },
+ {
+ // Note: Ideally fallback name should be consistent (e.g. "Unknown")
+ displayName: 'ReactComponent',
+ children: [],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -359,16 +357,20 @@ describe('ReactComponentTreeHook', () => {
var tree = {
displayName: 'div',
element,
- children: [{
- displayName: 'Bar',
- children: [],
- }, {
- displayName: 'Baz',
- children: [],
- }, {
- displayName: 'Unknown',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ {
+ displayName: 'Baz',
+ children: [],
+ },
+ {
+ displayName: 'Unknown',
+ children: [],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -390,16 +392,20 @@ describe('ReactComponentTreeHook', () => {
var tree = {
displayName: 'div',
element,
- children: [{
- displayName: 'Bar',
- children: [],
- }, {
- displayName: 'Baz',
- children: [],
- }, {
- displayName: 'Unknown',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ {
+ displayName: 'Baz',
+ children: [],
+ },
+ {
+ displayName: 'Unknown',
+ children: [],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -418,23 +424,31 @@ describe('ReactComponentTreeHook', () => {
);
var tree = {
displayName: 'div',
- children: [{
- displayName: 'p',
- children: [{
- displayName: 'span',
- children: [{
- displayName: '#text',
- text: 'Hi!',
- }],
- }, {
- displayName: '#text',
- text: 'Wow.',
- }],
- }, {
- displayName: 'hr',
- element:
,
- children: [],
- }],
+ children: [
+ {
+ displayName: 'p',
+ children: [
+ {
+ displayName: 'span',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi!',
+ },
+ ],
+ },
+ {
+ displayName: '#text',
+ text: 'Wow.',
+ },
+ ],
+ },
+ {
+ displayName: 'hr',
+ element:
,
+ children: [],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -450,11 +464,13 @@ describe('ReactComponentTreeHook', () => {
var tree = {
displayName: 'Foo',
element,
- children: [{
- displayName: 'div',
- element: ,
- children: [],
- }],
+ children: [
+ {
+ displayName: 'div',
+ element: ,
+ children: [],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -495,42 +511,59 @@ describe('ReactComponentTreeHook', () => {
var tree = {
displayName: 'Baz',
element,
- children: [{
- displayName: 'div',
- children: [{
- displayName: 'Foo',
- element: ,
- children: [{
- displayName: 'Qux',
- element: ,
- children: [],
- }],
- }, {
- displayName: 'Bar',
- children: [{
- displayName: 'h1',
- children: [{
- displayName: 'span',
- children: [{
- displayName: '#text',
- element: 'Hi,',
- text: 'Hi,',
- }],
- }, {
- displayName: '#text',
- text: 'Mom',
- element: 'Mom',
- }],
- }],
- }, {
- displayName: 'a',
- children: [{
- displayName: '#text',
- text: 'Click me.',
- element: 'Click me.',
- }],
- }],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [
+ {
+ displayName: 'Foo',
+ element: ,
+ children: [
+ {
+ displayName: 'Qux',
+ element: ,
+ children: [],
+ },
+ ],
+ },
+ {
+ displayName: 'Bar',
+ children: [
+ {
+ displayName: 'h1',
+ children: [
+ {
+ displayName: 'span',
+ children: [
+ {
+ displayName: '#text',
+ element: 'Hi,',
+ text: 'Hi,',
+ },
+ ],
+ },
+ {
+ displayName: '#text',
+ text: 'Mom',
+ element: 'Mom',
+ },
+ ],
+ },
+ ],
+ },
+ {
+ displayName: 'a',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Click me.',
+ element: 'Click me.',
+ },
+ ],
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -568,13 +601,16 @@ describe('ReactComponentTreeHook', () => {
var tree = {
displayName: 'div',
element,
- children: [{
- displayName: '#text',
- text: '1',
- }, {
- displayName: '#text',
- text: '2',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: '1',
+ },
+ {
+ displayName: '#text',
+ text: '2',
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -584,10 +620,12 @@ describe('ReactComponentTreeHook', () => {
var tree = {
displayName: 'div',
element,
- children: [{
- displayName: '#text',
- text: '1',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: '1',
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -597,10 +635,12 @@ describe('ReactComponentTreeHook', () => {
var tree = {
displayName: 'div',
element,
- children: [{
- displayName: '#text',
- text: '42',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: '42',
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -610,10 +650,12 @@ describe('ReactComponentTreeHook', () => {
var tree = {
displayName: 'div',
element,
- children: [{
- displayName: '#text',
- text: '0',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: '0',
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -634,23 +676,29 @@ describe('ReactComponentTreeHook', () => {
var tree = {
displayName: 'div',
element,
- children: [{
- displayName: '#text',
- text: 'hi',
- element: 'hi',
- }, {
- displayName: '#text',
- text: '42',
- element: 42,
- }, {
- displayName: 'Foo',
- element: ,
- children: [{
- displayName: 'div',
- element: ,
- children: [],
- }],
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'hi',
+ element: 'hi',
+ },
+ {
+ displayName: '#text',
+ text: '42',
+ element: 42,
+ },
+ {
+ displayName: 'Foo',
+ element: ,
+ children: [
+ {
+ displayName: 'div',
+ element: ,
+ children: [],
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -671,19 +719,23 @@ describe('ReactComponentTreeHook', () => {
var elementBefore = Hi.
;
var treeBefore = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
};
var elementAfter = Bye.
;
var treeAfter = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Bye.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
};
assertTreeMatches([
@@ -702,10 +754,12 @@ describe('ReactComponentTreeHook', () => {
var elementAfter = Hi.
;
var treeAfter = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
};
assertTreeMatches([
@@ -718,10 +772,12 @@ describe('ReactComponentTreeHook', () => {
var elementBefore = Hi.
;
var treeBefore = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
};
var elementAfter = ;
@@ -746,10 +802,12 @@ describe('ReactComponentTreeHook', () => {
var elementAfter = Hi.
;
var treeAfter = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
};
assertTreeMatches([
@@ -762,10 +820,12 @@ describe('ReactComponentTreeHook', () => {
var elementBefore = Hi.
;
var treeBefore = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
};
var elementAfter = ;
@@ -790,13 +850,16 @@ describe('ReactComponentTreeHook', () => {
var elementAfter = {'Hi.'}{'Bye.'}
;
var treeAfter = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }, {
- displayName: '#text',
- text: 'Bye.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
};
assertTreeMatches([
@@ -809,13 +872,16 @@ describe('ReactComponentTreeHook', () => {
var elementBefore = {'Hi.'}{'Bye.'}
;
var treeBefore = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }, {
- displayName: '#text',
- text: 'Bye.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
};
var elementAfter = ;
@@ -840,13 +906,16 @@ describe('ReactComponentTreeHook', () => {
var elementAfter = {'Hi.'}{'Bye.'}
;
var treeAfter = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }, {
- displayName: '#text',
- text: 'Bye.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
};
assertTreeMatches([
@@ -859,13 +928,16 @@ describe('ReactComponentTreeHook', () => {
var elementBefore = {'Hi.'}{'Bye.'}
;
var treeBefore = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }, {
- displayName: '#text',
- text: 'Bye.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
};
var elementAfter = ;
@@ -922,22 +994,27 @@ describe('ReactComponentTreeHook', () => {
var elementBefore = Hi.
;
var treeBefore = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
};
var elementAfter = {'Hi.'}{'Bye.'}
;
var treeAfter = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }, {
- displayName: '#text',
- text: 'Bye.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
};
assertTreeMatches([
@@ -950,22 +1027,27 @@ describe('ReactComponentTreeHook', () => {
var elementBefore = {'Hi.'}{'Bye.'}
;
var treeBefore = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }, {
- displayName: '#text',
- text: 'Bye.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
};
var elementAfter = Hi.
;
var treeAfter = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
};
assertTreeMatches([
[elementBefore, treeBefore],
@@ -977,25 +1059,31 @@ describe('ReactComponentTreeHook', () => {
var elementBefore = {'Hi.'}{'Bye.'}
;
var treeBefore = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }, {
- displayName: '#text',
- text: 'Bye.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
};
var elementAfter = {'Bye.'}{'Hi.'}
;
var treeAfter = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Bye.',
- }, {
- displayName: '#text',
- text: 'Hi.',
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
};
assertTreeMatches([
[elementBefore, treeBefore],
@@ -1012,19 +1100,26 @@ describe('ReactComponentTreeHook', () => {
);
var treeBefore = {
displayName: 'div',
- children: [{
- displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }, {
- displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Bye.',
- }],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ {
+ displayName: 'div',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
+ },
+ ],
};
var elementAfter = (
@@ -1035,19 +1130,26 @@ describe('ReactComponentTreeHook', () => {
);
var treeAfter = {
displayName: 'div',
- children: [{
- displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Bye.',
- }],
- }, {
- displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
+ },
+ {
+ displayName: 'div',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([
@@ -1065,19 +1167,26 @@ describe('ReactComponentTreeHook', () => {
);
var treeBefore = {
displayName: 'div',
- children: [{
- displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }, {
- displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Bye.',
- }],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ {
+ displayName: 'div',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
+ },
+ ],
};
var elementAfter = (
@@ -1088,19 +1197,26 @@ describe('ReactComponentTreeHook', () => {
);
var treeAfter = {
displayName: 'div',
- children: [{
- displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Bye.',
- }],
- }, {
- displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
+ },
+ {
+ displayName: 'div',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([
@@ -1121,19 +1237,23 @@ describe('ReactComponentTreeHook', () => {
var elementBefore =
;
var treeBefore = {
displayName: 'div',
- children: [{
- displayName: 'Foo',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ children: [],
+ },
+ ],
};
var elementAfter =
;
var treeAfter = {
displayName: 'div',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1143,32 +1263,40 @@ describe('ReactComponentTreeHook', () => {
});
it('updates a single composite child of the same type', () => {
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
var elementBefore = ;
var treeBefore = {
displayName: 'div',
- children: [{
- displayName: 'Foo',
- children: [{
- displayName: 'div',
- children: [],
- }],
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ children: [
+ {
+ displayName: 'div',
+ children: [],
+ },
+ ],
+ },
+ ],
};
var elementAfter =
;
var treeAfter = {
displayName: 'div',
- children: [{
- displayName: 'Foo',
- children: [{
- displayName: 'span',
- children: [],
- }],
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ children: [
+ {
+ displayName: 'span',
+ children: [],
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([
@@ -1191,10 +1319,12 @@ describe('ReactComponentTreeHook', () => {
var elementAfter =
;
var treeAfter = {
displayName: 'div',
- children: [{
- displayName: 'Foo',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1211,10 +1341,12 @@ describe('ReactComponentTreeHook', () => {
var elementBefore =
;
var treeBefore = {
displayName: 'div',
- children: [{
- displayName: 'Foo',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
@@ -1244,19 +1376,25 @@ describe('ReactComponentTreeHook', () => {
);
var tree1 = {
displayName: 'div',
- children: [{
- displayName: '#text',
- text: 'hi',
- }, {
- displayName: '#text',
- text: '42',
- }, {
- displayName: 'Foo',
- children: [{
- displayName: 'div',
- children: [],
- }],
- }],
+ children: [
+ {
+ displayName: '#text',
+ text: 'hi',
+ },
+ {
+ displayName: '#text',
+ text: '42',
+ },
+ {
+ displayName: 'Foo',
+ children: [
+ {
+ displayName: 'div',
+ children: [],
+ },
+ ],
+ },
+ ],
};
var element2 = (
@@ -1269,16 +1407,21 @@ describe('ReactComponentTreeHook', () => {
);
var tree2 = {
displayName: 'div',
- children: [{
- displayName: 'Foo',
- children: [{
- displayName: 'div',
- children: [],
- }],
- }, {
- displayName: '#text',
- text: 'hi',
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ children: [
+ {
+ displayName: 'div',
+ children: [],
+ },
+ ],
+ },
+ {
+ displayName: '#text',
+ text: 'hi',
+ },
+ ],
};
var element3 = (
@@ -1288,13 +1431,17 @@ describe('ReactComponentTreeHook', () => {
);
var tree3 = {
displayName: 'div',
- children: [{
- displayName: 'Foo',
- children: [{
- displayName: 'div',
- children: [],
- }],
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ children: [
+ {
+ displayName: 'div',
+ children: [],
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([
@@ -1307,26 +1454,30 @@ describe('ReactComponentTreeHook', () => {
describe('functional component', () => {
it('updates with a host child', () => {
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'div',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'span',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'span',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1336,7 +1487,7 @@ describe('ReactComponentTreeHook', () => {
});
it('updates from null to a host child', () => {
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
@@ -1349,10 +1500,12 @@ describe('ReactComponentTreeHook', () => {
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'div',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1362,17 +1515,19 @@ describe('ReactComponentTreeHook', () => {
});
it('updates from a host child to null', () => {
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'div',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [],
+ },
+ ],
};
var elementAfter = {null};
@@ -1392,26 +1547,30 @@ describe('ReactComponentTreeHook', () => {
return null;
}
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'div',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1425,26 +1584,30 @@ describe('ReactComponentTreeHook', () => {
return null;
}
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'div',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1458,7 +1621,7 @@ describe('ReactComponentTreeHook', () => {
return null;
}
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
@@ -1471,10 +1634,12 @@ describe('ReactComponentTreeHook', () => {
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1488,17 +1653,19 @@ describe('ReactComponentTreeHook', () => {
return null;
}
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
var elementAfter = {null};
@@ -1525,19 +1692,23 @@ describe('ReactComponentTreeHook', () => {
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'div',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'span',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'span',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1562,10 +1733,12 @@ describe('ReactComponentTreeHook', () => {
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'div',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1584,10 +1757,12 @@ describe('ReactComponentTreeHook', () => {
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'div',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [],
+ },
+ ],
};
var elementAfter = {null};
@@ -1618,19 +1793,23 @@ describe('ReactComponentTreeHook', () => {
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'div',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1655,19 +1834,23 @@ describe('ReactComponentTreeHook', () => {
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'div',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1698,10 +1881,12 @@ describe('ReactComponentTreeHook', () => {
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1726,10 +1911,12 @@ describe('ReactComponentTreeHook', () => {
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
var elementAfter = {null};
@@ -1762,28 +1949,39 @@ describe('ReactComponentTreeHook', () => {
var element = ;
var tree = {
displayName: 'article',
- children: [{
- displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- ownerDisplayName: 'Foo',
- children: [{
- displayName: 'div',
- ownerDisplayName: 'Bar',
- children: [{
- displayName: 'h1',
+ children: [
+ {
+ displayName: 'Foo',
+ children: [
+ {
+ displayName: 'Bar',
ownerDisplayName: 'Foo',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }, {
- displayName: '#text',
- text: ' Mom',
- }],
- }],
- }],
- }],
+ children: [
+ {
+ displayName: 'div',
+ ownerDisplayName: 'Bar',
+ children: [
+ {
+ displayName: 'h1',
+ ownerDisplayName: 'Foo',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ {
+ displayName: '#text',
+ text: ' Mom',
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -1809,28 +2007,40 @@ describe('ReactComponentTreeHook', () => {
}
ReactDOM.render(, node);
- ReactComponentTreeTestUtils.expectTree(barInstance._debugID, {
- displayName: 'Bar',
- parentDisplayName: 'Foo',
- parentID: fooInstance._debugID,
- children: [],
- }, 'Foo');
+ ReactComponentTreeTestUtils.expectTree(
+ barInstance._debugID,
+ {
+ displayName: 'Bar',
+ parentDisplayName: 'Foo',
+ parentID: fooInstance._debugID,
+ children: [],
+ },
+ 'Foo',
+ );
renderBar = false;
ReactDOM.render(, node);
ReactDOM.render(, node);
- ReactComponentTreeTestUtils.expectTree(barInstance._debugID, {
- displayName: 'Unknown',
- children: [],
- parentID: null,
- }, 'Foo');
+ ReactComponentTreeTestUtils.expectTree(
+ barInstance._debugID,
+ {
+ displayName: 'Unknown',
+ children: [],
+ parentID: null,
+ },
+ 'Foo',
+ );
ReactDOM.unmountComponentAtNode(node);
- ReactComponentTreeTestUtils.expectTree(barInstance._debugID, {
- displayName: 'Unknown',
- children: [],
- parentID: null,
- }, 'Foo');
+ ReactComponentTreeTestUtils.expectTree(
+ barInstance._debugID,
+ {
+ displayName: 'Unknown',
+ children: [],
+ parentID: null,
+ },
+ 'Foo',
+ );
});
it('reports update counts', () => {
@@ -1862,24 +2072,34 @@ describe('ReactComponentTreeHook', () => {
var node = document.createElement('div');
ReactDOM.render(, node);
- expectDev(ReactComponentTreeTestUtils.getRootDisplayNames()).toEqual(['div']);
+ expectDev(ReactComponentTreeTestUtils.getRootDisplayNames()).toEqual([
+ 'div',
+ ]);
ReactDOM.render(, node);
- expectDev(ReactComponentTreeTestUtils.getRootDisplayNames()).toEqual(['div']);
+ expectDev(ReactComponentTreeTestUtils.getRootDisplayNames()).toEqual([
+ 'div',
+ ]);
ReactDOM.unmountComponentAtNode(node);
expectDev(ReactComponentTreeTestUtils.getRootDisplayNames()).toEqual([]);
- expectDev(ReactComponentTreeTestUtils.getRegisteredDisplayNames()).toEqual([]);
+ expectDev(
+ ReactComponentTreeTestUtils.getRegisteredDisplayNames(),
+ ).toEqual([]);
});
it('registers inlined text nodes', () => {
var node = document.createElement('div');
ReactDOM.render(hi
, node);
- expectDev(ReactComponentTreeTestUtils.getRegisteredDisplayNames()).toEqual(['div', '#text']);
+ expectDev(
+ ReactComponentTreeTestUtils.getRegisteredDisplayNames(),
+ ).toEqual(['div', '#text']);
ReactDOM.unmountComponentAtNode(node);
- expectDev(ReactComponentTreeTestUtils.getRegisteredDisplayNames()).toEqual([]);
+ expectDev(
+ ReactComponentTreeTestUtils.getRegisteredDisplayNames(),
+ ).toEqual([]);
});
});
@@ -1949,42 +2169,59 @@ describe('ReactComponentTreeHook', () => {
var tree = {
displayName: 'Baz',
element,
- children: [{
- displayName: 'div',
- children: [{
- displayName: 'Foo',
- element: ,
- children: [{
- displayName: 'Qux',
- element: ,
- children: [],
- }],
- }, {
- displayName: 'Bar',
- children: [{
- displayName: 'h1',
- children: [{
- displayName: 'span',
- children: [{
- displayName: '#text',
- element: 'Hi,',
- text: 'Hi,',
- }],
- }, {
- displayName: '#text',
- text: 'Mom',
- element: 'Mom',
- }],
- }],
- }, {
- displayName: 'a',
- children: [{
- displayName: '#text',
- text: 'Click me.',
- element: 'Click me.',
- }],
- }],
- }],
+ children: [
+ {
+ displayName: 'div',
+ children: [
+ {
+ displayName: 'Foo',
+ element: ,
+ children: [
+ {
+ displayName: 'Qux',
+ element: ,
+ children: [],
+ },
+ ],
+ },
+ {
+ displayName: 'Bar',
+ children: [
+ {
+ displayName: 'h1',
+ children: [
+ {
+ displayName: 'span',
+ children: [
+ {
+ displayName: '#text',
+ element: 'Hi,',
+ text: 'Hi,',
+ },
+ ],
+ },
+ {
+ displayName: '#text',
+ text: 'Mom',
+ element: 'Mom',
+ },
+ ],
+ },
+ ],
+ },
+ {
+ displayName: 'a',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Click me.',
+ element: 'Click me.',
+ },
+ ],
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
diff --git a/src/renderers/__tests__/ReactComponentTreeHook-test.native.js b/src/renderers/__tests__/ReactComponentTreeHook-test.native.js
index 17a8fa4986..2de9bff4ef 100644
--- a/src/renderers/__tests__/ReactComponentTreeHook-test.native.js
+++ b/src/renderers/__tests__/ReactComponentTreeHook-test.native.js
@@ -157,16 +157,20 @@ describeStack('ReactComponentTreeHook', () => {
var tree = {
displayName: 'View',
element,
- children: [{
- displayName: 'Bar',
- children: [],
- }, {
- displayName: 'Baz',
- children: [],
- }, {
- displayName: 'Unknown',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ {
+ displayName: 'Baz',
+ children: [],
+ },
+ {
+ displayName: 'Unknown',
+ children: [],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -193,17 +197,21 @@ describeStack('ReactComponentTreeHook', () => {
var element = ;
var tree = {
displayName: 'View',
- children: [{
- displayName: 'Bar',
- children: [],
- }, {
- displayName: 'Baz',
- children: [],
- }, {
- // Note: Ideally fallback name should be consistent (e.g. "Unknown")
- displayName: 'ReactComponent',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ {
+ displayName: 'Baz',
+ children: [],
+ },
+ {
+ // Note: Ideally fallback name should be consistent (e.g. "Unknown")
+ displayName: 'ReactComponent',
+ children: [],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -236,16 +244,20 @@ describeStack('ReactComponentTreeHook', () => {
var element = ;
var tree = {
displayName: 'View',
- children: [{
- displayName: 'Bar',
- children: [],
- }, {
- displayName: 'Baz',
- children: [],
- }, {
- displayName: 'Unknown',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ {
+ displayName: 'Baz',
+ children: [],
+ },
+ {
+ displayName: 'Unknown',
+ children: [],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -266,16 +278,20 @@ describeStack('ReactComponentTreeHook', () => {
var element = ;
var tree = {
displayName: 'View',
- children: [{
- displayName: 'Bar',
- children: [],
- }, {
- displayName: 'Baz',
- children: [],
- }, {
- displayName: 'Unknown',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ {
+ displayName: 'Baz',
+ children: [],
+ },
+ {
+ displayName: 'Unknown',
+ children: [],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -294,24 +310,33 @@ describeStack('ReactComponentTreeHook', () => {
var tree = {
displayName: 'View',
element,
- children: [{
- displayName: 'View',
- children: [{
- displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- element: 'Hi!',
- text: 'Hi!',
- }],
- }],
- }],
- }, {
- displayName: 'Image',
- element: ,
- children: [],
- }],
+ children: [
+ {
+ displayName: 'View',
+ children: [
+ {
+ displayName: 'Text',
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ element: 'Hi!',
+ text: 'Hi!',
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ {
+ displayName: 'Image',
+ element: ,
+ children: [],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -327,11 +352,13 @@ describeStack('ReactComponentTreeHook', () => {
var tree = {
displayName: 'Foo',
element,
- children: [{
- displayName: 'Image',
- element: ,
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Image',
+ element: ,
+ children: [],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -371,38 +398,54 @@ describeStack('ReactComponentTreeHook', () => {
var tree = {
displayName: 'Baz',
element,
- children: [{
- displayName: 'View',
- children: [{
- displayName: 'Foo',
- element: ,
- children: [{
- displayName: 'Qux',
- element: ,
- children: [],
- }],
- }, {
- displayName: 'Bar',
- children: [{
- displayName: 'View',
- children: [{
- displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- element: 'Hi,',
- text: 'Hi,',
- }],
- }],
- }],
- }],
- }, {
- displayName: 'Image',
- element: ,
- children: [],
- }],
- }],
+ children: [
+ {
+ displayName: 'View',
+ children: [
+ {
+ displayName: 'Foo',
+ element: ,
+ children: [
+ {
+ displayName: 'Qux',
+ element: ,
+ children: [],
+ },
+ ],
+ },
+ {
+ displayName: 'Bar',
+ children: [
+ {
+ displayName: 'View',
+ children: [
+ {
+ displayName: 'Text',
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ element: 'Hi,',
+ text: 'Hi,',
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ {
+ displayName: 'Image',
+ element: ,
+ children: [],
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -439,16 +482,21 @@ describeStack('ReactComponentTreeHook', () => {
var element = {'1'}{2};
var tree = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: '1',
- }, {
- displayName: '#text',
- text: '2',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: '1',
+ },
+ {
+ displayName: '#text',
+ text: '2',
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -457,13 +505,17 @@ describeStack('ReactComponentTreeHook', () => {
var element = {'1'};
var tree = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: '1',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: '1',
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -472,13 +524,17 @@ describeStack('ReactComponentTreeHook', () => {
var element = {42};
var tree = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: '42',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: '42',
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -487,13 +543,17 @@ describeStack('ReactComponentTreeHook', () => {
var element = {0};
var tree = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: '0',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: '0',
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -513,23 +573,30 @@ describeStack('ReactComponentTreeHook', () => {
var tree = {
displayName: 'View',
element,
- children: [{
- displayName: 'Foo',
- element: ,
- children: [{
- displayName: 'Image',
- element: ,
- children: [],
- }],
- }, {
- displayName: 'Foo',
- element: ,
- children: [{
- displayName: 'Image',
- element: ,
- children: [],
- }],
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ element: ,
+ children: [
+ {
+ displayName: 'Image',
+ element: ,
+ children: [],
+ },
+ ],
+ },
+ {
+ displayName: 'Foo',
+ element: ,
+ children: [
+ {
+ displayName: 'Image',
+ element: ,
+ children: [],
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([element, tree]);
});
@@ -541,25 +608,33 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = Hi.;
var treeBefore = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ ],
};
var elementAfter = Bye.;
var treeAfter = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Bye.',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([
@@ -572,22 +647,28 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = ;
var treeBefore = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [],
+ },
+ ],
};
var elementAfter = Hi.;
var treeAfter = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([
@@ -600,22 +681,28 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = Hi.;
var treeBefore = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -628,25 +715,32 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = ;
var treeBefore = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [],
+ },
+ ],
};
var elementAfter = {'Hi.'}{'Bye.'};
var treeAfter = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }, {
- displayName: '#text',
- text: 'Bye.',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([
@@ -659,25 +753,32 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = {'Hi.'}{'Bye.'};
var treeBefore = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }, {
- displayName: '#text',
- text: 'Bye.',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
[elementBefore, treeBefore],
@@ -689,28 +790,37 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = Hi.;
var treeBefore = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ ],
};
var elementAfter = {'Hi.'}{'Bye.'};
var treeAfter = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }, {
- displayName: '#text',
- text: 'Bye.',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([
@@ -723,28 +833,37 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = {'Hi.'}{'Bye.'};
var treeBefore = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }, {
- displayName: '#text',
- text: 'Bye.',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
+ },
+ ],
};
var elementAfter = Hi.;
var treeAfter = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([
[elementBefore, treeBefore],
@@ -756,31 +875,41 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = {'Hi.'}{'Bye.'};
var treeBefore = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }, {
- displayName: '#text',
- text: 'Bye.',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
+ },
+ ],
};
var elementAfter = {'Bye.'}{'Hi.'};
var treeAfter = {
displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Bye.',
- }, {
- displayName: '#text',
- text: 'Hi.',
- }],
- }],
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([
[elementBefore, treeBefore],
@@ -797,25 +926,36 @@ describeStack('ReactComponentTreeHook', () => {
);
var treeBefore = {
displayName: 'View',
- children: [{
- displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }],
- }, {
- displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Bye.',
- }],
- }],
- }],
+ children: [
+ {
+ displayName: 'Text',
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ ],
+ },
+ {
+ displayName: 'Text',
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
+ },
+ ],
+ },
+ ],
};
var elementAfter = (
@@ -826,25 +966,36 @@ describeStack('ReactComponentTreeHook', () => {
);
var treeAfter = {
displayName: 'View',
- children: [{
- displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Bye.',
- }],
- }],
- }, {
- displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }],
- }],
+ children: [
+ {
+ displayName: 'Text',
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
+ },
+ ],
+ },
+ {
+ displayName: 'Text',
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([
@@ -862,25 +1013,36 @@ describeStack('ReactComponentTreeHook', () => {
);
var treeBefore = {
displayName: 'View',
- children: [{
- displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }],
- }, {
- displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Bye.',
- }],
- }],
- }],
+ children: [
+ {
+ displayName: 'Text',
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ ],
+ },
+ {
+ displayName: 'Text',
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
+ },
+ ],
+ },
+ ],
};
var elementAfter = (
@@ -891,25 +1053,36 @@ describeStack('ReactComponentTreeHook', () => {
);
var treeAfter = {
displayName: 'View',
- children: [{
- displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Bye.',
- }],
- }],
- }, {
- displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }],
- }],
+ children: [
+ {
+ displayName: 'Text',
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Bye.',
+ },
+ ],
+ },
+ ],
+ },
+ {
+ displayName: 'Text',
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([
@@ -930,19 +1103,23 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = ;
var treeBefore = {
displayName: 'View',
- children: [{
- displayName: 'Foo',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'View',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -952,32 +1129,40 @@ describeStack('ReactComponentTreeHook', () => {
});
it('updates a single composite child of the same type', () => {
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
var elementBefore = ;
var treeBefore = {
displayName: 'View',
- children: [{
- displayName: 'Foo',
- children: [{
- displayName: 'View',
- children: [],
- }],
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ children: [
+ {
+ displayName: 'View',
+ children: [],
+ },
+ ],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'View',
- children: [{
- displayName: 'Foo',
- children: [{
- displayName: 'Image',
- children: [],
- }],
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ children: [
+ {
+ displayName: 'Image',
+ children: [],
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([
@@ -1000,10 +1185,12 @@ describeStack('ReactComponentTreeHook', () => {
var elementAfter = ;
var treeAfter = {
displayName: 'View',
- children: [{
- displayName: 'Foo',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1020,10 +1207,12 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = ;
var treeBefore = {
displayName: 'View',
- children: [{
- displayName: 'Foo',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
@@ -1053,31 +1242,45 @@ describeStack('ReactComponentTreeHook', () => {
);
var tree1 = {
displayName: 'View',
- children: [{
- displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'hi',
- }],
- }],
- }, {
- displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: '42',
- }],
- }],
- }, {
- displayName: 'Foo',
- children: [{
- displayName: 'View',
- children: [],
- }],
- }],
+ children: [
+ {
+ displayName: 'Text',
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'hi',
+ },
+ ],
+ },
+ ],
+ },
+ {
+ displayName: 'Text',
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: '42',
+ },
+ ],
+ },
+ ],
+ },
+ {
+ displayName: 'Foo',
+ children: [
+ {
+ displayName: 'View',
+ children: [],
+ },
+ ],
+ },
+ ],
};
var element2 = (
@@ -1090,22 +1293,31 @@ describeStack('ReactComponentTreeHook', () => {
);
var tree2 = {
displayName: 'View',
- children: [{
- displayName: 'Foo',
- children: [{
- displayName: 'View',
- children: [],
- }],
- }, {
- displayName: 'Text',
- children: [{
- displayName: 'RCText',
- children: [{
- displayName: '#text',
- text: 'hi',
- }],
- }],
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ children: [
+ {
+ displayName: 'View',
+ children: [],
+ },
+ ],
+ },
+ {
+ displayName: 'Text',
+ children: [
+ {
+ displayName: 'RCText',
+ children: [
+ {
+ displayName: '#text',
+ text: 'hi',
+ },
+ ],
+ },
+ ],
+ },
+ ],
};
var element3 = (
@@ -1115,13 +1327,17 @@ describeStack('ReactComponentTreeHook', () => {
);
var tree3 = {
displayName: 'View',
- children: [{
- displayName: 'Foo',
- children: [{
- displayName: 'View',
- children: [],
- }],
- }],
+ children: [
+ {
+ displayName: 'Foo',
+ children: [
+ {
+ displayName: 'View',
+ children: [],
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([
@@ -1134,26 +1350,30 @@ describeStack('ReactComponentTreeHook', () => {
describe('functional component', () => {
it('updates with a host child', () => {
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'View',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'View',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'Image',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Image',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1163,7 +1383,7 @@ describeStack('ReactComponentTreeHook', () => {
});
it('updates from null to a host child', () => {
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
@@ -1176,10 +1396,12 @@ describeStack('ReactComponentTreeHook', () => {
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'View',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'View',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1189,17 +1411,19 @@ describeStack('ReactComponentTreeHook', () => {
});
it('updates from a host child to null', () => {
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'View',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'View',
+ children: [],
+ },
+ ],
};
var elementAfter = {null};
@@ -1219,26 +1443,30 @@ describeStack('ReactComponentTreeHook', () => {
return null;
}
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'View',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'View',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1252,26 +1480,30 @@ describeStack('ReactComponentTreeHook', () => {
return null;
}
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'View',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'View',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1285,7 +1517,7 @@ describeStack('ReactComponentTreeHook', () => {
return null;
}
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
@@ -1298,10 +1530,12 @@ describeStack('ReactComponentTreeHook', () => {
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1315,17 +1549,19 @@ describeStack('ReactComponentTreeHook', () => {
return null;
}
- function Foo({ children }) {
+ function Foo({children}) {
return children;
}
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
var elementAfter = {null};
@@ -1352,19 +1588,23 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'View',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'View',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'Image',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Image',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1389,10 +1629,12 @@ describeStack('ReactComponentTreeHook', () => {
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'View',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'View',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1411,10 +1653,12 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'View',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'View',
+ children: [],
+ },
+ ],
};
var elementAfter = {null};
@@ -1445,19 +1689,23 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'View',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'View',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1482,19 +1730,23 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'View',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'View',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1525,10 +1777,12 @@ describeStack('ReactComponentTreeHook', () => {
var elementAfter = ;
var treeAfter = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
assertTreeMatches([
@@ -1553,10 +1807,12 @@ describeStack('ReactComponentTreeHook', () => {
var elementBefore = ;
var treeBefore = {
displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- children: [],
- }],
+ children: [
+ {
+ displayName: 'Bar',
+ children: [],
+ },
+ ],
};
var elementAfter = {null};
@@ -1588,40 +1844,57 @@ describeStack('ReactComponentTreeHook', () => {
var element = ;
var tree = {
displayName: 'View',
- children: [{
- displayName: 'Foo',
- children: [{
- displayName: 'Bar',
- ownerDisplayName: 'Foo',
- children: [{
- displayName: 'View',
- ownerDisplayName: 'Bar',
- children: [{
- displayName: 'Text',
+ children: [
+ {
+ displayName: 'Foo',
+ children: [
+ {
+ displayName: 'Bar',
ownerDisplayName: 'Foo',
- children: [{
- displayName: 'RCText',
- ownerDisplayName: 'Text',
- children: [{
- displayName: '#text',
- text: 'Hi.',
- }],
- }],
- }, {
- displayName: 'Text',
- ownerDisplayName: 'Bar',
- children: [{
- displayName: 'RCText',
- ownerDisplayName: 'Text',
- children: [{
- displayName: '#text',
- text: 'Mom',
- }],
- }],
- }],
- }],
- }],
- }],
+ children: [
+ {
+ displayName: 'View',
+ ownerDisplayName: 'Bar',
+ children: [
+ {
+ displayName: 'Text',
+ ownerDisplayName: 'Foo',
+ children: [
+ {
+ displayName: 'RCText',
+ ownerDisplayName: 'Text',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Hi.',
+ },
+ ],
+ },
+ ],
+ },
+ {
+ displayName: 'Text',
+ ownerDisplayName: 'Bar',
+ children: [
+ {
+ displayName: 'RCText',
+ ownerDisplayName: 'Text',
+ children: [
+ {
+ displayName: '#text',
+ text: 'Mom',
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
};
assertTreeMatches([element, tree], {includeOwnerDisplayName: true});
});
@@ -1646,27 +1919,39 @@ describeStack('ReactComponentTreeHook', () => {
}
ReactNative.render(, 1);
- ReactComponentTreeTestUtils.expectTree(barInstance._debugID, {
- displayName: 'Bar',
- parentDisplayName: 'Foo',
- parentID: fooInstance._debugID,
- children: [],
- }, 'Foo');
+ ReactComponentTreeTestUtils.expectTree(
+ barInstance._debugID,
+ {
+ displayName: 'Bar',
+ parentDisplayName: 'Foo',
+ parentID: fooInstance._debugID,
+ children: [],
+ },
+ 'Foo',
+ );
renderBar = false;
ReactNative.render(, 1);
- ReactComponentTreeTestUtils.expectTree(barInstance._debugID, {
- displayName: 'Unknown',
- children: [],
- parentID: null,
- }, 'Foo');
+ ReactComponentTreeTestUtils.expectTree(
+ barInstance._debugID,
+ {
+ displayName: 'Unknown',
+ children: [],
+ parentID: null,
+ },
+ 'Foo',
+ );
ReactNative.unmountComponentAtNode(1);
- ReactComponentTreeTestUtils.expectTree(barInstance._debugID, {
- displayName: 'Unknown',
- children: [],
- parentID: null,
- }, 'Foo');
+ ReactComponentTreeTestUtils.expectTree(
+ barInstance._debugID,
+ {
+ displayName: 'Unknown',
+ children: [],
+ parentID: null,
+ },
+ 'Foo',
+ );
});
it('reports update counts', () => {
@@ -1694,13 +1979,18 @@ describeStack('ReactComponentTreeHook', () => {
it('does not report top-level wrapper as a root', () => {
ReactNative.render(, 1);
- expectDev(ReactComponentTreeTestUtils.getRootDisplayNames()).toEqual(['View']);
+ expectDev(ReactComponentTreeTestUtils.getRootDisplayNames()).toEqual([
+ 'View',
+ ]);
ReactNative.render(, 1);
- expectDev(ReactComponentTreeTestUtils.getRootDisplayNames()).toEqual(['View']);
+ expectDev(ReactComponentTreeTestUtils.getRootDisplayNames()).toEqual([
+ 'View',
+ ]);
ReactNative.unmountComponentAtNode(1);
expectDev(ReactComponentTreeTestUtils.getRootDisplayNames()).toEqual([]);
- expectDev(ReactComponentTreeTestUtils.getRegisteredDisplayNames()).toEqual([]);
+ expectDev(ReactComponentTreeTestUtils.getRegisteredDisplayNames()).toEqual([
+ ]);
});
});
diff --git a/src/renderers/__tests__/ReactCompositeComponent-test.js b/src/renderers/__tests__/ReactCompositeComponent-test.js
index 29953610e0..6f82e6f01a 100644
--- a/src/renderers/__tests__/ReactCompositeComponent-test.js
+++ b/src/renderers/__tests__/ReactCompositeComponent-test.js
@@ -22,7 +22,6 @@ var ReactPropTypes;
var ReactTestUtils;
describe('ReactCompositeComponent', () => {
-
beforeEach(() => {
jest.resetModules();
React = require('react');
@@ -42,9 +41,9 @@ describe('ReactCompositeComponent', () => {
render() {
var toggleActivatedState = this._toggleActivatedState;
- return !this.state.activated ?
- :
- ;
+ return !this.state.activated
+ ?
+ : ;
}
};
@@ -59,9 +58,9 @@ describe('ReactCompositeComponent', () => {
render() {
var className = this.props.anchorClassOn ? 'anchorClass' : '';
- return this.props.renderAnchor ?
- :
- ;
+ return this.props.renderAnchor
+ ?
+ : ;
}
};
});
@@ -139,19 +138,22 @@ describe('ReactCompositeComponent', () => {
var container = document.createElement('div');
var instance = ReactDOM.render(
,
- container
+ container,
);
- ReactDOM.render( // Warm any cache
+ ReactDOM.render(
+ // Warm any cache
,
- container
+ container,
);
- ReactDOM.render( // Clear out the anchor
+ ReactDOM.render(
+ // Clear out the anchor
,
- container
+ container,
);
- ReactDOM.render( // rerender
+ ReactDOM.render(
+ // rerender
,
- container
+ container,
);
expect(instance.getAnchor().className).toBe('');
});
@@ -188,7 +190,7 @@ describe('ReactCompositeComponent', () => {
expectDev(console.error.calls.count()).toBe(1);
var explicitlyBound = mountedInstance.methodToBeExplicitlyBound.bind(
- mountedInstance
+ mountedInstance,
);
expectDev(console.error.calls.count()).toBe(2);
var autoBound = mountedInstance.methodAutoBound;
@@ -199,7 +201,6 @@ describe('ReactCompositeComponent', () => {
expect(explicitlyBound.call(mountedInstance)).toBe(mountedInstance);
expect(autoBound.call(mountedInstance)).toBe(mountedInstance);
-
});
it('should not pass this to getDefaultProps', () => {
@@ -227,10 +228,14 @@ describe('ReactCompositeComponent', () => {
var instance1 = ReactTestUtils.renderIntoDocument();
expect(instance1.props).toEqual({prop: 'testKey'});
- var instance2 = ReactTestUtils.renderIntoDocument();
+ var instance2 = ReactTestUtils.renderIntoDocument(
+ ,
+ );
expect(instance2.props).toEqual({prop: 'testKey'});
- var instance3 = ReactTestUtils.renderIntoDocument();
+ var instance3 = ReactTestUtils.renderIntoDocument(
+ ,
+ );
expect(instance3.props).toEqual({prop: null});
});
@@ -279,9 +284,9 @@ describe('ReactCompositeComponent', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Can only update a mounted or mounting component. This usually means ' +
- 'you called setState, replaceState, or forceUpdate on an unmounted ' +
- 'component. This is a no-op.\n\nPlease check the code for the ' +
- 'Component component.'
+ 'you called setState, replaceState, or forceUpdate on an unmounted ' +
+ 'component. This is a no-op.\n\nPlease check the code for the ' +
+ 'Component component.',
);
});
@@ -323,9 +328,9 @@ describe('ReactCompositeComponent', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Can only update a mounted or mounting component. This usually means ' +
- 'you called setState, replaceState, or forceUpdate on an unmounted ' +
- 'component. This is a no-op.\n\nPlease check the code for the ' +
- 'Component component.'
+ 'you called setState, replaceState, or forceUpdate on an unmounted ' +
+ 'component. This is a no-op.\n\nPlease check the code for the ' +
+ 'Component component.',
);
});
@@ -357,7 +362,6 @@ describe('ReactCompositeComponent', () => {
expect(cbCalled).toBe(false);
});
-
it('should warn about `setState` in render', () => {
spyOn(console, 'error');
@@ -373,7 +377,7 @@ describe('ReactCompositeComponent', () => {
renderPasses++;
renderedState = this.state.value;
if (this.state.value === 0) {
- this.setState({ value: 1 });
+ this.setState({value: 1});
}
return ;
}
@@ -386,9 +390,9 @@ describe('ReactCompositeComponent', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'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 state; constructor side-effects are ' +
- 'an anti-pattern, but can be moved to `componentWillMount`.'
+ "`render` or another component's constructor). Render methods should " +
+ 'be a pure function of props and state; constructor side-effects are ' +
+ 'an anti-pattern, but can be moved to `componentWillMount`.',
);
// The setState call is queued and then executed as a second pass. This
@@ -417,7 +421,7 @@ describe('ReactCompositeComponent', () => {
getChildContext() {
if (this.state.value === 0) {
- this.setState({ value: 1 });
+ this.setState({value: 1});
}
}
@@ -434,7 +438,7 @@ describe('ReactCompositeComponent', () => {
expect(instance.state.value).toBe(1);
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
- 'Warning: setState(...): Cannot call setState() inside getChildContext()'
+ 'Warning: setState(...): Cannot call setState() inside getChildContext()',
);
});
@@ -507,7 +511,7 @@ describe('ReactCompositeComponent', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Component.shouldComponentUpdate(): Returned undefined instead of a ' +
- 'boolean value. Make sure to return true or false.'
+ 'boolean value. Make sure to return true or false.',
);
});
@@ -515,8 +519,7 @@ describe('ReactCompositeComponent', () => {
spyOn(console, 'error');
class Component extends React.Component {
- componentDidUnmount = () => {
- };
+ componentDidUnmount = () => {};
render() {
return ;
@@ -528,8 +531,8 @@ describe('ReactCompositeComponent', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(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()?'
+ 'componentDidUnmount(). But there is no such lifecycle method. ' +
+ 'Did you mean componentWillUnmount()?',
);
});
@@ -639,7 +642,7 @@ describe('ReactCompositeComponent', () => {
}
parentInstance = ReactTestUtils.renderIntoDocument(
-
+ ,
);
expect(parentInstance.state.flag).toBe(false);
@@ -691,10 +694,7 @@ describe('ReactCompositeComponent', () => {
}
}
-
- var wrapper = ReactTestUtils.renderIntoDocument(
-
- );
+ var wrapper = ReactTestUtils.renderIntoDocument();
expect(wrapper.refs.parent.state.flag).toEqual(true);
expect(wrapper.refs.child.context).toEqual({flag: true});
@@ -999,7 +999,7 @@ describe('ReactCompositeComponent', () => {
B2
,
- div
+ div,
);
parentInstance.setState({
@@ -1030,9 +1030,9 @@ describe('ReactCompositeComponent', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toMatch(
'Render methods should be a pure function of props and state; ' +
- 'triggering nested component updates from render is not allowed. If ' +
- 'necessary, trigger nested updates in componentDidUpdate.\n\nCheck the ' +
- 'render method of Outer.'
+ 'triggering nested component updates from render is not allowed. If ' +
+ 'necessary, trigger nested updates in componentDidUpdate.\n\nCheck the ' +
+ 'render method of Outer.',
);
});
@@ -1295,7 +1295,7 @@ describe('ReactCompositeComponent', () => {
class Foo extends React.Component {
constructor(props) {
- var _props = { idx: props.idx + '!' };
+ var _props = {idx: props.idx + '!'};
super(_props);
}
@@ -1311,9 +1311,8 @@ describe('ReactCompositeComponent', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(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.'
+ "up the same props that your component's constructor was passed.",
);
-
});
it('should only call componentWillUnmount once', () => {
@@ -1344,7 +1343,7 @@ describe('ReactCompositeComponent', () => {
var container = document.createElement('div');
- var setRef = (ref) => {
+ var setRef = ref => {
if (ref) {
app = ref;
}
@@ -1397,5 +1396,4 @@ describe('ReactCompositeComponent', () => {
'B componentDidMount',
]);
});
-
});
diff --git a/src/renderers/__tests__/ReactCompositeComponentDOMMinimalism-test.js b/src/renderers/__tests__/ReactCompositeComponentDOMMinimalism-test.js
index aa9972a161..3391470f81 100644
--- a/src/renderers/__tests__/ReactCompositeComponentDOMMinimalism-test.js
+++ b/src/renderers/__tests__/ReactCompositeComponentDOMMinimalism-test.js
@@ -28,7 +28,6 @@ var expectSingleChildlessDiv;
* nodes.
*/
describe('ReactCompositeComponentDOMMinimalism', () => {
-
beforeEach(() => {
React = require('react');
ReactDOM = require('react-dom');
@@ -96,5 +95,4 @@ describe('ReactCompositeComponentDOMMinimalism', () => {
expect(el.children[0].tagName).toBe('UL');
expect(el.children[0].children.length).toBe(0);
});
-
});
diff --git a/src/renderers/__tests__/ReactCompositeComponentNestedState-test.js b/src/renderers/__tests__/ReactCompositeComponentNestedState-test.js
index a0eba24154..4480a2231f 100644
--- a/src/renderers/__tests__/ReactCompositeComponentNestedState-test.js
+++ b/src/renderers/__tests__/ReactCompositeComponentNestedState-test.js
@@ -16,7 +16,6 @@ var ReactDOM;
var ReactTestUtils;
describe('ReactCompositeComponentNestedState-state', () => {
-
beforeEach(() => {
React = require('react');
ReactDOM = require('react-dom');
@@ -27,7 +26,7 @@ describe('ReactCompositeComponentNestedState-state', () => {
class ParentComponent extends React.Component {
state = {color: 'blue'};
- handleColor = (color) => {
+ handleColor = color => {
this.props.logger('parent-handleColor', this.state.color);
this.setState({color: color}, function() {
this.props.logger('parent-after-setState', this.state.color);
@@ -56,13 +55,24 @@ describe('ReactCompositeComponentNestedState-state', () => {
handleHue = (shade, color) => {
this.props.logger('handleHue', this.state.hue, this.props.color);
this.props.onSelectColor(color);
- this.setState(function(state, props) {
- this.props.logger('setState-this', this.state.hue, this.props.color);
- this.props.logger('setState-args', state.hue, props.color);
- return {hue: shade + ' ' + props.color};
- }, function() {
- this.props.logger('after-setState', this.state.hue, this.props.color);
- });
+ this.setState(
+ function(state, props) {
+ this.props.logger(
+ 'setState-this',
+ this.state.hue,
+ this.props.color,
+ );
+ this.props.logger('setState-args', state.hue, props.color);
+ return {hue: shade + ' ' + props.color};
+ },
+ function() {
+ this.props.logger(
+ 'after-setState',
+ this.state.hue,
+ this.props.color,
+ );
+ },
+ );
};
render() {
@@ -91,15 +101,10 @@ describe('ReactCompositeComponentNestedState-state', () => {
var logger = jest.fn();
- void ReactDOM.render(
- ,
- container
- );
+ void ReactDOM.render(, container);
// click "light green"
- ReactTestUtils.Simulate.click(
- container.childNodes[0].childNodes[3]
- );
+ ReactTestUtils.Simulate.click(container.childNodes[0].childNodes[3]);
expect(logger.mock.calls).toEqual([
['parent-render', 'blue'],
diff --git a/src/renderers/__tests__/ReactCompositeComponentState-test.js b/src/renderers/__tests__/ReactCompositeComponentState-test.js
index 9aa97f2646..6bed124cfd 100644
--- a/src/renderers/__tests__/ReactCompositeComponentState-test.js
+++ b/src/renderers/__tests__/ReactCompositeComponentState-test.js
@@ -18,7 +18,6 @@ var ReactDOMFeatureFlags;
var TestComponent;
describe('ReactCompositeComponent-state', () => {
-
beforeEach(() => {
React = require('react');
@@ -38,7 +37,7 @@ describe('ReactCompositeComponent-state', () => {
setFavoriteColor: function(nextColor) {
this.setState(
{color: nextColor},
- this.peekAtCallback('setFavoriteColor')
+ this.peekAtCallback('setFavoriteColor'),
);
},
@@ -59,7 +58,7 @@ describe('ReactCompositeComponent-state', () => {
});
this.setState(
{color: 'sunrise'},
- this.peekAtCallback('setState-sunrise')
+ this.peekAtCallback('setState-sunrise'),
);
this.setState(function(state) {
this.peekAtState('after-setState-sunrise', state);
@@ -67,7 +66,7 @@ describe('ReactCompositeComponent-state', () => {
this.peekAtState('componentWillMount-after-sunrise');
this.setState(
{color: 'orange'},
- this.peekAtCallback('setState-orange')
+ this.peekAtCallback('setState-orange'),
);
this.setState(function(state) {
this.peekAtState('after-setState-orange', state);
@@ -79,7 +78,7 @@ describe('ReactCompositeComponent-state', () => {
this.peekAtState('componentDidMount-start');
this.setState(
{color: 'yellow'},
- this.peekAtCallback('setState-yellow')
+ this.peekAtCallback('setState-yellow'),
);
this.peekAtState('componentDidMount-end');
},
@@ -97,7 +96,7 @@ describe('ReactCompositeComponent-state', () => {
this.peekAtState('before-setState-again-receiveProps', state);
return {color: newProps.nextColor};
},
- this.peekAtCallback('setState-receiveProps')
+ this.peekAtCallback('setState-receiveProps'),
);
this.setState(function(state) {
this.peekAtState('after-setState-receiveProps', state);
@@ -138,12 +137,12 @@ describe('ReactCompositeComponent-state', () => {
container,
function peekAtInitialCallback() {
this.peekAtState('initial-callback');
- }
+ },
);
ReactDOM.render(
,
container,
- instance.peekAtCallback('setProps')
+ instance.peekAtCallback('setProps'),
);
instance.setFavoriteColor('blue');
instance.forceUpdate(instance.peekAtCallback('forceUpdate'));
@@ -191,9 +190,7 @@ describe('ReactCompositeComponent-state', () => {
// from the queue. In Fiber, we keep updates in the queue to support
// replaceState(prevState => newState).
// TODO: Fix Stack to match Fiber.
- expected.push(
- ['before-setState-receiveProps', 'yellow'],
- );
+ expected.push(['before-setState-receiveProps', 'yellow']);
}
expected.push(
@@ -232,7 +229,6 @@ describe('ReactCompositeComponent-state', () => {
expect(stateListener.mock.calls.join('\n')).toEqual(expected.join('\n'));
});
-
it('should call componentDidUpdate of children first', () => {
var container = document.createElement('div');
@@ -242,7 +238,7 @@ describe('ReactCompositeComponent-state', () => {
var parent = null;
class Child extends React.Component {
- state = {bar:false};
+ state = {bar: false};
componentDidMount() {
child = this;
}
@@ -266,7 +262,7 @@ describe('ReactCompositeComponent-state', () => {
}
class Parent extends React.Component {
- state = {foo:false};
+ state = {foo: false};
componentDidMount() {
parent = this;
}
@@ -281,40 +277,36 @@ describe('ReactCompositeComponent-state', () => {
ReactDOM.render(, container);
ReactDOM.unstable_batchedUpdates(() => {
- parent.setState({ foo: true });
- child.setState({ bar: true });
+ parent.setState({foo: true});
+ child.setState({bar: true});
});
// When we render changes top-down in a batch, children's componentDidUpdate
// happens before the parent.
- expect(ops).toEqual([
- 'child did update',
- 'parent did update',
- ]);
+ expect(ops).toEqual(['child did update', 'parent did update']);
shouldUpdate = false;
ops = [];
ReactDOM.unstable_batchedUpdates(() => {
- parent.setState({ foo: false });
- child.setState({ bar: false });
+ parent.setState({foo: false});
+ child.setState({bar: false});
});
// We expect the same thing to happen if we bail out in the middle.
expect(ops).toEqual(
ReactDOMFeatureFlags.useFiber
? [
- // Fiber works as expected
- 'child did update',
- 'parent did update',
- ]
+ // Fiber works as expected
+ 'child did update',
+ 'parent did update',
+ ]
: [
- // Stack treats these as two separate updates and therefore the order
- // is inverse.
- 'parent did update',
- 'child did update',
- ]
+ // Stack treats these as two separate updates and therefore the order
+ // is inverse.
+ 'parent did update',
+ 'child did update',
+ ],
);
-
});
it('should batch unmounts', () => {
@@ -396,8 +388,10 @@ describe('ReactCompositeComponent-state', () => {
}
shouldComponentUpdate(nextProps, nextState) {
log.push(
- 'scu from ' + Object.keys(this.state) +
- ' to ' + Object.keys(nextState)
+ 'scu from ' +
+ Object.keys(this.state) +
+ ' to ' +
+ Object.keys(nextState),
);
return false;
}
@@ -409,10 +403,7 @@ describe('ReactCompositeComponent-state', () => {
expect(log.length).toBe(1);
test.setState({c: 0});
expect(log.length).toBe(2);
- expect(log).toEqual([
- 'scu from a to a,b',
- 'scu from a,b to a,b,c',
- ]);
+ expect(log).toEqual(['scu from a to a,b', 'scu from a,b to a,b,c']);
});
it('should treat assigning to this.state inside cWRP as a replaceState, with a warning', () => {
@@ -420,17 +411,21 @@ describe('ReactCompositeComponent-state', () => {
let ops = [];
class Test extends React.Component {
- state = { step: 1, extra: true };
+ state = {step: 1, extra: true};
componentWillReceiveProps() {
- this.setState({ step: 2 }, () => {
+ this.setState({step: 2}, () => {
// Tests that earlier setState callbacks are not dropped
- ops.push(`callback -- step: ${this.state.step}, extra: ${!!this.state.extra}`);
+ ops.push(
+ `callback -- step: ${this.state.step}, extra: ${!!this.state.extra}`,
+ );
});
// Treat like replaceState
- this.state = { step: 3 };
+ this.state = {step: 3};
}
render() {
- ops.push(`render -- step: ${this.state.step}, extra: ${!!this.state.extra}`);
+ ops.push(
+ `render -- step: ${this.state.step}, extra: ${!!this.state.extra}`,
+ );
return null;
}
}
@@ -449,8 +444,8 @@ describe('ReactCompositeComponent-state', () => {
expect(console.error.calls.count()).toEqual(1);
expect(console.error.calls.argsFor(0)[0]).toEqual(
'Warning: Test.componentWillReceiveProps(): Assigning directly to ' +
- 'this.state is deprecated (except inside a component\'s constructor). ' +
- 'Use setState instead.'
+ "this.state is deprecated (except inside a component's constructor). " +
+ 'Use setState instead.',
);
});
});
diff --git a/src/renderers/__tests__/ReactEmptyComponent-test.js b/src/renderers/__tests__/ReactEmptyComponent-test.js
index d9985d24dd..06ac9c483f 100644
--- a/src/renderers/__tests__/ReactEmptyComponent-test.js
+++ b/src/renderers/__tests__/ReactEmptyComponent-test.js
@@ -80,21 +80,17 @@ describe('ReactEmptyComponent', () => {
ReactTestUtils.renderIntoDocument();
}).toThrowError(
'Component.render(): A valid React element (or null) must be returned. You may ' +
- 'have returned undefined, an array or some other invalid object.'
+ 'have returned undefined, an array or some other invalid object.',
);
});
it('should be able to switch between rendering null and a normal tag', () => {
- var instance1 =
- ;
- var instance2 =
- ;
+ var instance1 = (
+
+ );
+ var instance2 = (
+
+ );
ReactTestUtils.renderIntoDocument(instance1);
ReactTestUtils.renderIntoDocument(instance2);
@@ -107,18 +103,16 @@ describe('ReactEmptyComponent', () => {
});
it('should be able to switch in a list of children', () => {
- var instance1 =
- ;
+ var instance1 = (
+
+ );
ReactTestUtils.renderIntoDocument(
{instance1}
{instance1}
{instance1}
-
+ ,
);
expect(log.calls.count()).toBe(6);
@@ -130,36 +124,31 @@ describe('ReactEmptyComponent', () => {
expect(log.calls.argsFor(5)[0].tagName).toBe('DIV');
});
- it('should distinguish between a script placeholder and an actual script tag',
- () => {
- var instance1 =
-
;
- var instance2 =
-
;
+ it('should distinguish between a script placeholder and an actual script tag', () => {
+ var instance1 = (
+
+ );
+ var instance2 = (
+
+ );
- expect(function() {
- ReactTestUtils.renderIntoDocument(instance1);
- }).not.toThrow();
- expect(function() {
- ReactTestUtils.renderIntoDocument(instance2);
- }).not.toThrow();
+ expect(function() {
+ ReactTestUtils.renderIntoDocument(instance1);
+ }).not.toThrow();
+ expect(function() {
+ ReactTestUtils.renderIntoDocument(instance2);
+ }).not.toThrow();
- 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);
- }
- );
+ 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);
+ });
- it('should have findDOMNode return null when multiple layers of composite ' +
- 'components render to the same null placeholder',
+ it(
+ 'should have findDOMNode return null when multiple layers of composite ' +
+ 'components render to the same null placeholder',
() => {
class GrandChild extends React.Component {
render() {
@@ -173,16 +162,12 @@ describe('ReactEmptyComponent', () => {
}
}
- var instance1 =
-
;
- var instance2 =
-
;
+ var instance1 = (
+
+ );
+ var instance2 = (
+
+ );
expect(function() {
ReactTestUtils.renderIntoDocument(instance1);
@@ -196,7 +181,7 @@ describe('ReactEmptyComponent', () => {
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');
- }
+ },
);
it('works when switching components', () => {
@@ -259,9 +244,7 @@ describe('ReactEmptyComponent', () => {
// Stack does not implement this.
expect(function() {
ReactDOM.render(null, div);
- }).toThrowError(
- 'ReactDOM.render(): Invalid component element.'
- );
+ }).toThrowError('ReactDOM.render(): Invalid component element.');
}
} finally {
ReactFeatureFlags.disableNewFiberFeatures = true;
diff --git a/src/renderers/__tests__/ReactErrorBoundaries-test.js b/src/renderers/__tests__/ReactErrorBoundaries-test.js
index 5bac8b1a5f..d9a34dc5e6 100644
--- a/src/renderers/__tests__/ReactErrorBoundaries-test.js
+++ b/src/renderers/__tests__/ReactErrorBoundaries-test.js
@@ -148,7 +148,9 @@ describe('ReactErrorBoundaries', () => {
log.push('BrokenComponentWillReceiveProps componentDidMount');
}
componentWillReceiveProps() {
- log.push('BrokenComponentWillReceiveProps componentWillReceiveProps [!]');
+ log.push(
+ 'BrokenComponentWillReceiveProps componentWillReceiveProps [!]',
+ );
throw new Error('Hello');
}
componentWillUpdate() {
@@ -273,7 +275,9 @@ describe('ReactErrorBoundaries', () => {
return
{this.props.children}
;
}
componentWillMount() {
- log.push('BrokenComponentWillMountErrorBoundary componentWillMount [!]');
+ log.push(
+ 'BrokenComponentWillMountErrorBoundary componentWillMount [!]',
+ );
throw new Error('Hello');
}
componentDidMount() {
@@ -593,7 +597,7 @@ describe('ReactErrorBoundaries', () => {
,
- container3
+ container3,
);
expect(container1.firstChild.textContent).toBe('Before 1');
expect(container2.firstChild).toBe(null);
@@ -605,7 +609,7 @@ describe('ReactErrorBoundaries', () => {
After 3
,
- container3
+ container3,
);
expect(container1.firstChild.textContent).toBe('After 1');
expect(container2.firstChild.textContent).toBe('After 2');
@@ -625,11 +629,9 @@ describe('ReactErrorBoundaries', () => {
,
- container
- );
- expect(container.firstChild.textContent).toBe(
- 'Caught an error: Hello.'
+ container,
);
+ expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
'ErrorBoundary constructor',
'ErrorBoundary componentWillMount',
@@ -637,27 +639,27 @@ describe('ReactErrorBoundaries', () => {
'BrokenRender constructor',
'BrokenRender componentWillMount',
'BrokenRender render [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Fiber mounts with null children before capturing error
- 'ErrorBoundary componentDidMount',
- // Catch and render an error message
- 'ErrorBoundary unstable_handleError',
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ] : [
- // Catch and render an error message
- 'ErrorBoundary unstable_handleError',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidMount',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Fiber mounts with null children before capturing error
+ 'ErrorBoundary componentDidMount',
+ // Catch and render an error message
+ 'ErrorBoundary unstable_handleError',
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ // Catch and render an error message
+ 'ErrorBoundary unstable_handleError',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidMount',
+ ]),
]);
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('renders an error state if child throws in constructor', () => {
@@ -666,7 +668,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -674,27 +676,27 @@ describe('ReactErrorBoundaries', () => {
'ErrorBoundary componentWillMount',
'ErrorBoundary render success',
'BrokenConstructor constructor [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Fiber mounts with null children before capturing error
- 'ErrorBoundary componentDidMount',
- // Catch and render an error message
- 'ErrorBoundary unstable_handleError',
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ] : [
- // Catch and render an error message
- 'ErrorBoundary unstable_handleError',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidMount',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Fiber mounts with null children before capturing error
+ 'ErrorBoundary componentDidMount',
+ // Catch and render an error message
+ 'ErrorBoundary unstable_handleError',
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ // Catch and render an error message
+ 'ErrorBoundary unstable_handleError',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidMount',
+ ]),
]);
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('renders an error state if child throws in componentWillMount', () => {
@@ -703,7 +705,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -712,25 +714,25 @@ describe('ReactErrorBoundaries', () => {
'ErrorBoundary render success',
'BrokenComponentWillMount constructor',
'BrokenComponentWillMount componentWillMount [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- 'ErrorBoundary componentDidMount',
- 'ErrorBoundary unstable_handleError',
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ] : [
- // Catch and render an error message
- 'ErrorBoundary unstable_handleError',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidMount',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ 'ErrorBoundary componentDidMount',
+ 'ErrorBoundary unstable_handleError',
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ // Catch and render an error message
+ 'ErrorBoundary unstable_handleError',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidMount',
+ ]),
]);
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('renders an error state if context provider throws in componentWillMount', () => {
@@ -752,7 +754,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
});
@@ -780,16 +782,14 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
});
it('mounts the error message if mounting fails', () => {
function renderError(error) {
- return (
-
- );
+ return
;
}
var container = document.createElement('div');
@@ -797,7 +797,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(log).toEqual([
'ErrorBoundary constructor',
@@ -806,27 +806,29 @@ describe('ReactErrorBoundaries', () => {
'BrokenRender constructor',
'BrokenRender componentWillMount',
'BrokenRender render [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- 'ErrorBoundary componentDidMount',
- 'ErrorBoundary unstable_handleError',
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- 'ErrorMessage constructor',
- 'ErrorMessage componentWillMount',
- 'ErrorMessage render',
- 'ErrorMessage componentDidMount',
- 'ErrorBoundary componentDidUpdate',
- ] : [
- // Handle the error:
- 'ErrorBoundary unstable_handleError',
- 'ErrorBoundary render error',
- // Mount the error message:
- 'ErrorMessage constructor',
- 'ErrorMessage componentWillMount',
- 'ErrorMessage render',
- 'ErrorMessage componentDidMount',
- 'ErrorBoundary componentDidMount',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ 'ErrorBoundary componentDidMount',
+ 'ErrorBoundary unstable_handleError',
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ 'ErrorMessage constructor',
+ 'ErrorMessage componentWillMount',
+ 'ErrorMessage render',
+ 'ErrorMessage componentDidMount',
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ // Handle the error:
+ 'ErrorBoundary unstable_handleError',
+ 'ErrorBoundary render error',
+ // Mount the error message:
+ 'ErrorMessage constructor',
+ 'ErrorMessage componentWillMount',
+ 'ErrorMessage render',
+ 'ErrorMessage componentDidMount',
+ 'ErrorBoundary componentDidMount',
+ ]),
]);
log.length = 0;
@@ -845,7 +847,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -858,44 +860,44 @@ describe('ReactErrorBoundaries', () => {
'BrokenRender constructor',
'BrokenRender componentWillMount',
'BrokenRender render [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- // In Fiber, failed error boundaries render null before attempting to recover
- 'RetryErrorBoundary componentDidMount',
- 'RetryErrorBoundary unstable_handleError [!]',
- 'ErrorBoundary componentDidMount',
- // Retry
- 'RetryErrorBoundary render',
- 'BrokenRender constructor',
- 'BrokenRender componentWillMount',
- 'BrokenRender render [!]',
- // This time, the error propagates to the higher boundary
- 'RetryErrorBoundary componentWillUnmount',
- 'ErrorBoundary unstable_handleError',
- // Render the error
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ] : [
- // The first error boundary catches the error.
- // However, it doesn't adjust its state so next render will also fail.
- 'RetryErrorBoundary unstable_handleError [*]',
- 'RetryErrorBoundary render',
- 'BrokenRender constructor',
- 'BrokenRender componentWillMount',
- 'BrokenRender render [!]',
- // This time, the error propagates to the higher boundary
- 'ErrorBoundary unstable_handleError',
- // Render the error
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidMount',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // In Fiber, failed error boundaries render null before attempting to recover
+ 'RetryErrorBoundary componentDidMount',
+ 'RetryErrorBoundary unstable_handleError [!]',
+ 'ErrorBoundary componentDidMount',
+ // Retry
+ 'RetryErrorBoundary render',
+ 'BrokenRender constructor',
+ 'BrokenRender componentWillMount',
+ 'BrokenRender render [!]',
+ // This time, the error propagates to the higher boundary
+ 'RetryErrorBoundary componentWillUnmount',
+ 'ErrorBoundary unstable_handleError',
+ // Render the error
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ // The first error boundary catches the error.
+ // However, it doesn't adjust its state so next render will also fail.
+ 'RetryErrorBoundary unstable_handleError [*]',
+ 'RetryErrorBoundary render',
+ 'BrokenRender constructor',
+ 'BrokenRender componentWillMount',
+ 'BrokenRender render [!]',
+ // This time, the error propagates to the higher boundary
+ 'ErrorBoundary unstable_handleError',
+ // Render the error
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidMount',
+ ]),
]);
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('propagates errors inside boundary during componentWillMount', () => {
@@ -904,7 +906,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -914,25 +916,25 @@ describe('ReactErrorBoundaries', () => {
'BrokenComponentWillMountErrorBoundary constructor',
'BrokenComponentWillMountErrorBoundary componentWillMount [!]',
// The error propagates to the higher boundary
- ...(ReactDOMFeatureFlags.useFiber ? [
- 'ErrorBoundary componentDidMount',
- 'ErrorBoundary unstable_handleError',
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ] : [
- 'ErrorBoundary unstable_handleError',
- // Render the error
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidMount',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ 'ErrorBoundary componentDidMount',
+ 'ErrorBoundary unstable_handleError',
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ 'ErrorBoundary unstable_handleError',
+ // Render the error
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidMount',
+ ]),
]);
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('propagates errors inside boundary while rendering error state', () => {
@@ -943,7 +945,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -958,36 +960,36 @@ describe('ReactErrorBoundaries', () => {
'BrokenRender render [!]',
// The first error boundary catches the error
// It adjusts state but throws displaying the message
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Finish mounting with null children
- 'BrokenRenderErrorBoundary componentDidMount',
- // Attempt to handle the error
- 'BrokenRenderErrorBoundary unstable_handleError',
- 'ErrorBoundary componentDidMount',
- 'BrokenRenderErrorBoundary render error [!]',
- // Boundary fails with new error, propagate to next boundary
- 'BrokenRenderErrorBoundary componentWillUnmount',
- // Attempt to handle the error again
- 'ErrorBoundary unstable_handleError',
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ] : [
- 'BrokenRenderErrorBoundary unstable_handleError',
- 'BrokenRenderErrorBoundary render error [!]',
- // The error propagates to the higher boundary
- 'ErrorBoundary unstable_handleError',
- // Render the error
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidMount',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Finish mounting with null children
+ 'BrokenRenderErrorBoundary componentDidMount',
+ // Attempt to handle the error
+ 'BrokenRenderErrorBoundary unstable_handleError',
+ 'ErrorBoundary componentDidMount',
+ 'BrokenRenderErrorBoundary render error [!]',
+ // Boundary fails with new error, propagate to next boundary
+ 'BrokenRenderErrorBoundary componentWillUnmount',
+ // Attempt to handle the error again
+ 'ErrorBoundary unstable_handleError',
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ 'BrokenRenderErrorBoundary unstable_handleError',
+ 'BrokenRenderErrorBoundary render error [!]',
+ // The error propagates to the higher boundary
+ 'ErrorBoundary unstable_handleError',
+ // Render the error
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidMount',
+ ]),
]);
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('does not call componentWillUnmount when aborting initial mount', () => {
@@ -998,7 +1000,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -1013,28 +1015,28 @@ describe('ReactErrorBoundaries', () => {
'BrokenRender constructor',
'BrokenRender componentWillMount',
'BrokenRender render [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Finish mounting with null children
- 'ErrorBoundary componentDidMount',
- // Handle the error
- 'ErrorBoundary unstable_handleError',
- // Render the error message
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ] : [
- 'ErrorBoundary unstable_handleError',
- // Render the error message
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidMount',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Finish mounting with null children
+ 'ErrorBoundary componentDidMount',
+ // Handle the error
+ 'ErrorBoundary unstable_handleError',
+ // Render the error message
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ 'ErrorBoundary unstable_handleError',
+ // Render the error message
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidMount',
+ ]),
]);
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('resets refs if mounting aborts', () => {
@@ -1051,7 +1053,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -1062,26 +1064,28 @@ describe('ReactErrorBoundaries', () => {
'BrokenRender componentWillMount',
'BrokenRender render [!]',
// Handle error:
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Finish mounting with null children
- 'ErrorBoundary componentDidMount',
- // Handle the error
- 'ErrorBoundary unstable_handleError',
- // Render the error message
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- 'Error message ref is set to [object HTMLDivElement]',
- 'ErrorBoundary componentDidUpdate',
- ] : [
- 'ErrorBoundary unstable_handleError',
- // Stack reconciler resets ref on update, as it doesn't know ref was never set.
- // This is unnecessary, and Fiber doesn't do it:
- 'Child ref is set to null',
- 'ErrorBoundary render error',
- // Ref to error message should get set:
- 'Error message ref is set to [object HTMLDivElement]',
- 'ErrorBoundary componentDidMount',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Finish mounting with null children
+ 'ErrorBoundary componentDidMount',
+ // Handle the error
+ 'ErrorBoundary unstable_handleError',
+ // Render the error message
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ 'Error message ref is set to [object HTMLDivElement]',
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ 'ErrorBoundary unstable_handleError',
+ // Stack reconciler resets ref on update, as it doesn't know ref was never set.
+ // This is unnecessary, and Fiber doesn't do it:
+ 'Child ref is set to null',
+ 'ErrorBoundary render error',
+ // Ref to error message should get set:
+ 'Error message ref is set to [object HTMLDivElement]',
+ 'ErrorBoundary componentDidMount',
+ ]),
]);
log.length = 0;
@@ -1098,7 +1102,7 @@ describe('ReactErrorBoundaries', () => {
Mounted successfully.
,
- container
+ container,
);
expect(container.firstChild.textContent).toBe('Mounted successfully.');
expect(log).toEqual([
@@ -1110,9 +1114,7 @@ describe('ReactErrorBoundaries', () => {
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('catches if child throws in constructor during update', () => {
@@ -1121,7 +1123,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
log.length = 0;
@@ -1131,7 +1133,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -1147,31 +1149,31 @@ describe('ReactErrorBoundaries', () => {
'Normal2 render',
// BrokenConstructor will abort rendering:
'BrokenConstructor constructor [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Finish updating with null children
- 'Normal componentWillUnmount',
- 'ErrorBoundary componentDidUpdate',
- // Handle the error
- 'ErrorBoundary unstable_handleError',
- // Render the error message
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ] : [
- 'ErrorBoundary unstable_handleError',
- // Stack unmounts first, then renders:
- 'Normal componentWillUnmount',
- 'ErrorBoundary render error',
- // Normal2 does not get lifefycle because it was never mounted
- 'ErrorBoundary componentDidUpdate',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Finish updating with null children
+ 'Normal componentWillUnmount',
+ 'ErrorBoundary componentDidUpdate',
+ // Handle the error
+ 'ErrorBoundary unstable_handleError',
+ // Render the error message
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ 'ErrorBoundary unstable_handleError',
+ // Stack unmounts first, then renders:
+ 'Normal componentWillUnmount',
+ 'ErrorBoundary render error',
+ // Normal2 does not get lifefycle because it was never mounted
+ 'ErrorBoundary componentDidUpdate',
+ ]),
]);
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('catches if child throws in componentWillMount during update', () => {
@@ -1180,7 +1182,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
log.length = 0;
@@ -1190,7 +1192,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -1207,31 +1209,31 @@ describe('ReactErrorBoundaries', () => {
// BrokenComponentWillMount will abort rendering:
'BrokenComponentWillMount constructor',
'BrokenComponentWillMount componentWillMount [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Finish updating with null children
- 'Normal componentWillUnmount',
- 'ErrorBoundary componentDidUpdate',
- // Handle the error
- 'ErrorBoundary unstable_handleError',
- // Render the error message
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ] : [
- 'ErrorBoundary unstable_handleError',
- // Stack unmounts first, then renders:
- 'Normal componentWillUnmount',
- 'ErrorBoundary render error',
- // Normal2 does not get lifefycle because it was never mounted
- 'ErrorBoundary componentDidUpdate',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Finish updating with null children
+ 'Normal componentWillUnmount',
+ 'ErrorBoundary componentDidUpdate',
+ // Handle the error
+ 'ErrorBoundary unstable_handleError',
+ // Render the error message
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ 'ErrorBoundary unstable_handleError',
+ // Stack unmounts first, then renders:
+ 'Normal componentWillUnmount',
+ 'ErrorBoundary render error',
+ // Normal2 does not get lifefycle because it was never mounted
+ 'ErrorBoundary componentDidUpdate',
+ ]),
]);
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('catches if child throws in componentWillReceiveProps during update', () => {
@@ -1241,7 +1243,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
log.length = 0;
@@ -1250,7 +1252,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -1262,31 +1264,31 @@ describe('ReactErrorBoundaries', () => {
'Normal render',
// BrokenComponentWillReceiveProps will abort rendering:
'BrokenComponentWillReceiveProps componentWillReceiveProps [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Finish updating with null children
- 'Normal componentWillUnmount',
- 'BrokenComponentWillReceiveProps componentWillUnmount',
- 'ErrorBoundary componentDidUpdate',
- // Handle the error
- 'ErrorBoundary unstable_handleError',
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ] : [
- 'ErrorBoundary unstable_handleError',
- // Stack unmounts first, then renders:
- 'Normal componentWillUnmount',
- 'BrokenComponentWillReceiveProps componentWillUnmount',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Finish updating with null children
+ 'Normal componentWillUnmount',
+ 'BrokenComponentWillReceiveProps componentWillUnmount',
+ 'ErrorBoundary componentDidUpdate',
+ // Handle the error
+ 'ErrorBoundary unstable_handleError',
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ 'ErrorBoundary unstable_handleError',
+ // Stack unmounts first, then renders:
+ 'Normal componentWillUnmount',
+ 'BrokenComponentWillReceiveProps componentWillUnmount',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]),
]);
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('catches if child throws in componentWillUpdate during update', () => {
@@ -1296,7 +1298,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
log.length = 0;
@@ -1305,7 +1307,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -1318,31 +1320,31 @@ describe('ReactErrorBoundaries', () => {
// BrokenComponentWillUpdate will abort rendering:
'BrokenComponentWillUpdate componentWillReceiveProps',
'BrokenComponentWillUpdate componentWillUpdate [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Finish updating with null children
- 'Normal componentWillUnmount',
- 'BrokenComponentWillUpdate componentWillUnmount',
- 'ErrorBoundary componentDidUpdate',
- // Handle the error
- 'ErrorBoundary unstable_handleError',
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ] : [
- 'ErrorBoundary unstable_handleError',
- // Stack unmounts first, then renders:
- 'Normal componentWillUnmount',
- 'BrokenComponentWillUpdate componentWillUnmount',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Finish updating with null children
+ 'Normal componentWillUnmount',
+ 'BrokenComponentWillUpdate componentWillUnmount',
+ 'ErrorBoundary componentDidUpdate',
+ // Handle the error
+ 'ErrorBoundary unstable_handleError',
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ 'ErrorBoundary unstable_handleError',
+ // Stack unmounts first, then renders:
+ 'Normal componentWillUnmount',
+ 'BrokenComponentWillUpdate componentWillUnmount',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]),
]);
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('catches if child throws in render during update', () => {
@@ -1351,7 +1353,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
log.length = 0;
@@ -1361,7 +1363,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -1379,30 +1381,30 @@ describe('ReactErrorBoundaries', () => {
'BrokenRender constructor',
'BrokenRender componentWillMount',
'BrokenRender render [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Finish updating with null children
- 'Normal componentWillUnmount',
- 'ErrorBoundary componentDidUpdate',
- // Handle the error
- 'ErrorBoundary unstable_handleError',
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ] : [
- 'ErrorBoundary unstable_handleError',
- // Stack unmounts first, then renders:
- 'Normal componentWillUnmount',
- 'ErrorBoundary render error',
- // Normal2 does not get lifefycle because it was never mounted
- 'ErrorBoundary componentDidUpdate',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Finish updating with null children
+ 'Normal componentWillUnmount',
+ 'ErrorBoundary componentDidUpdate',
+ // Handle the error
+ 'ErrorBoundary unstable_handleError',
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ 'ErrorBoundary unstable_handleError',
+ // Stack unmounts first, then renders:
+ 'Normal componentWillUnmount',
+ 'ErrorBoundary render error',
+ // Normal2 does not get lifefycle because it was never mounted
+ 'ErrorBoundary componentDidUpdate',
+ ]),
]);
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('keeps refs up-to-date during updates', () => {
@@ -1421,7 +1423,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(log).toEqual([
'ErrorBoundary constructor',
@@ -1438,7 +1440,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -1449,20 +1451,22 @@ describe('ReactErrorBoundaries', () => {
'BrokenRender constructor',
'BrokenRender componentWillMount',
'BrokenRender render [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Finish updating with null children
- 'Child1 ref is set to null',
- 'ErrorBoundary componentDidUpdate',
- // Handle the error
- 'ErrorBoundary unstable_handleError',
- 'ErrorBoundary componentWillUpdate',
- 'ErrorBoundary render error',
- ] : [
- 'ErrorBoundary unstable_handleError',
- // Stack resets ref first, renders later
- 'Child1 ref is set to null',
- 'ErrorBoundary render error',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Finish updating with null children
+ 'Child1 ref is set to null',
+ 'ErrorBoundary componentDidUpdate',
+ // Handle the error
+ 'ErrorBoundary unstable_handleError',
+ 'ErrorBoundary componentWillUpdate',
+ 'ErrorBoundary render error',
+ ]
+ : [
+ 'ErrorBoundary unstable_handleError',
+ // Stack resets ref first, renders later
+ 'Child1 ref is set to null',
+ 'ErrorBoundary render error',
+ ]),
'Error message ref is set to [object HTMLDivElement]',
// Child2 ref is never set because its mounting aborted
'ErrorBoundary componentDidUpdate',
@@ -1484,7 +1488,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
log.length = 0;
@@ -1492,7 +1496,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -1505,40 +1509,40 @@ describe('ReactErrorBoundaries', () => {
'BrokenComponentWillUnmount render',
// Unmounting throws:
'BrokenComponentWillUnmount componentWillUnmount [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Fiber proceeds with lifecycles despite errors
- 'Normal componentWillUnmount',
- // The components have updated in this phase
- 'BrokenComponentWillUnmount componentDidUpdate',
- 'ErrorBoundary componentDidUpdate',
- // Now that commit phase is done, Fiber unmounts the boundary's children
- 'BrokenComponentWillUnmount componentWillUnmount [!]',
- 'ErrorBoundary unstable_handleError',
- // The initial render was aborted, so
- // Fiber retries from the root.
- 'ErrorBoundary componentWillUpdate',
- // Render an error now (stack will do it later)
- 'ErrorBoundary render error',
- // Attempt to unmount previous child:
- // Done
- 'ErrorBoundary componentDidUpdate',
- ] : [
- // Stack will handle error immediately
- 'ErrorBoundary unstable_handleError',
- // Attempt to unmount previous children:
- 'BrokenComponentWillUnmount componentWillUnmount [!]',
- 'Normal componentWillUnmount',
- // Render an error now (Fiber will do it earlier)
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Fiber proceeds with lifecycles despite errors
+ 'Normal componentWillUnmount',
+ // The components have updated in this phase
+ 'BrokenComponentWillUnmount componentDidUpdate',
+ 'ErrorBoundary componentDidUpdate',
+ // Now that commit phase is done, Fiber unmounts the boundary's children
+ 'BrokenComponentWillUnmount componentWillUnmount [!]',
+ 'ErrorBoundary unstable_handleError',
+ // The initial render was aborted, so
+ // Fiber retries from the root.
+ 'ErrorBoundary componentWillUpdate',
+ // Render an error now (stack will do it later)
+ 'ErrorBoundary render error',
+ // Attempt to unmount previous child:
+ // Done
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ // Stack will handle error immediately
+ 'ErrorBoundary unstable_handleError',
+ // Attempt to unmount previous children:
+ 'BrokenComponentWillUnmount componentWillUnmount [!]',
+ 'Normal componentWillUnmount',
+ // Render an error now (Fiber will do it earlier)
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]),
]);
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('recovers from nested componentWillUnmount errors on update', () => {
@@ -1550,7 +1554,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
log.length = 0;
@@ -1560,7 +1564,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -1576,38 +1580,38 @@ describe('ReactErrorBoundaries', () => {
'BrokenComponentWillUnmount render',
// Unmounting throws:
'BrokenComponentWillUnmount componentWillUnmount [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Fiber proceeds with lifecycles despite errors
- 'BrokenComponentWillUnmount componentDidUpdate',
- 'Normal componentDidUpdate',
- 'ErrorBoundary componentDidUpdate',
- 'Normal componentWillUnmount',
- 'BrokenComponentWillUnmount componentWillUnmount [!]',
- // Now that commit phase is done, Fiber handles errors
- 'ErrorBoundary unstable_handleError',
- // The initial render was aborted, so
- // Fiber retries from the root.
- 'ErrorBoundary componentWillUpdate',
- // Render an error now (stack will do it later)
- 'ErrorBoundary render error',
- // Done
- 'ErrorBoundary componentDidUpdate',
- ] : [
- 'ErrorBoundary unstable_handleError',
- // Attempt to unmount previous children:
- 'Normal componentWillUnmount',
- 'BrokenComponentWillUnmount componentWillUnmount [!]',
- // Stack calls lifecycles first, then renders.
- 'ErrorBoundary render error',
- 'ErrorBoundary componentDidUpdate',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Fiber proceeds with lifecycles despite errors
+ 'BrokenComponentWillUnmount componentDidUpdate',
+ 'Normal componentDidUpdate',
+ 'ErrorBoundary componentDidUpdate',
+ 'Normal componentWillUnmount',
+ 'BrokenComponentWillUnmount componentWillUnmount [!]',
+ // Now that commit phase is done, Fiber handles errors
+ 'ErrorBoundary unstable_handleError',
+ // The initial render was aborted, so
+ // Fiber retries from the root.
+ 'ErrorBoundary componentWillUpdate',
+ // Render an error now (stack will do it later)
+ 'ErrorBoundary render error',
+ // Done
+ 'ErrorBoundary componentDidUpdate',
+ ]
+ : [
+ 'ErrorBoundary unstable_handleError',
+ // Attempt to unmount previous children:
+ 'Normal componentWillUnmount',
+ 'BrokenComponentWillUnmount componentWillUnmount [!]',
+ // Stack calls lifecycles first, then renders.
+ 'ErrorBoundary render error',
+ 'ErrorBoundary componentDidUpdate',
+ ]),
]);
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('picks the right boundary when handling unmounting errors', () => {
@@ -1620,20 +1624,29 @@ describe('ReactErrorBoundaries', () => {
var container = document.createElement('div');
ReactDOM.render(
-
-
+
+
,
- container
+ container,
);
log.length = 0;
ReactDOM.render(
-
-
+
+
,
- container
+ container,
);
expect(container.textContent).toBe('Caught an inner error: Hello.');
expect(log).toEqual([
@@ -1647,29 +1660,31 @@ describe('ReactErrorBoundaries', () => {
'InnerErrorBoundary render success',
// Try unmounting child
'BrokenComponentWillUnmount componentWillUnmount [!]',
- ...(ReactDOMFeatureFlags.useFiber ? [
- // Fiber proceeds with lifecycles despite errors
- // Inner and outer boundaries have updated in this phase
- 'InnerErrorBoundary componentDidUpdate',
- 'OuterErrorBoundary componentDidUpdate',
- // Now that commit phase is done, Fiber handles errors
- // Only inner boundary receives the error:
- 'InnerErrorBoundary unstable_handleError',
- 'InnerErrorBoundary componentWillUpdate',
- // Render an error now
- 'InnerErrorBoundary render error',
- // In Fiber, this was a local update to the
- // inner boundary so only its hook fires
- 'InnerErrorBoundary componentDidUpdate',
- ] : [
- // Stack will handle error immediately
- 'InnerErrorBoundary unstable_handleError',
- 'InnerErrorBoundary render error',
- // In stack, this was a part of the update to the
- // outer boundary so both lifecycles fire
- 'InnerErrorBoundary componentDidUpdate',
- 'OuterErrorBoundary componentDidUpdate',
- ]),
+ ...(ReactDOMFeatureFlags.useFiber
+ ? [
+ // Fiber proceeds with lifecycles despite errors
+ // Inner and outer boundaries have updated in this phase
+ 'InnerErrorBoundary componentDidUpdate',
+ 'OuterErrorBoundary componentDidUpdate',
+ // Now that commit phase is done, Fiber handles errors
+ // Only inner boundary receives the error:
+ 'InnerErrorBoundary unstable_handleError',
+ 'InnerErrorBoundary componentWillUpdate',
+ // Render an error now
+ 'InnerErrorBoundary render error',
+ // In Fiber, this was a local update to the
+ // inner boundary so only its hook fires
+ 'InnerErrorBoundary componentDidUpdate',
+ ]
+ : [
+ // Stack will handle error immediately
+ 'InnerErrorBoundary unstable_handleError',
+ 'InnerErrorBoundary render error',
+ // In stack, this was a part of the update to the
+ // outer boundary so both lifecycles fire
+ 'InnerErrorBoundary componentDidUpdate',
+ 'OuterErrorBoundary componentDidUpdate',
+ ]),
]);
log.length = 0;
@@ -1686,14 +1701,14 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
ReactDOM.render(
,
- container
+ container,
);
// Error boundary doesn't retry by itself:
expect(container.textContent).toBe('Caught an error: Hello.');
@@ -1704,7 +1719,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.textContent).not.toContain('Caught an error');
expect(log).toEqual([
@@ -1734,7 +1749,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.textContent).toBe('Caught an error: Hello.');
@@ -1742,7 +1757,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.textContent).toBe('Caught an error: Hello.');
@@ -1752,7 +1767,7 @@ describe('ReactErrorBoundaries', () => {
ReactDOM.unmountComponentAtNode(container);
});
- it('doesn\'t get into inconsistent state during removals', () => {
+ it("doesn't get into inconsistent state during removals", () => {
var container = document.createElement('div');
ReactDOM.render(
@@ -1760,7 +1775,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
ReactDOM.render(, container);
@@ -1768,12 +1783,10 @@ describe('ReactErrorBoundaries', () => {
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
- it('doesn\'t get into inconsistent state during additions', () => {
+ it("doesn't get into inconsistent state during additions", () => {
var container = document.createElement('div');
ReactDOM.render(, container);
ReactDOM.render(
@@ -1782,18 +1795,16 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.textContent).toBe('Caught an error: Hello.');
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
- it('doesn\'t get into inconsistent state during reorders', () => {
+ it("doesn't get into inconsistent state during reorders", () => {
function getAMixOfNormalAndBrokenRenderElements() {
var elements = [];
for (var i = 0; i < 100; i++) {
@@ -1827,7 +1838,7 @@ describe('ReactErrorBoundaries', () => {
{getAMixOfNormalAndBrokenRenderElements()}
,
- container
+ container,
);
expect(container.textContent).not.toContain('Caught an error');
@@ -1836,15 +1847,13 @@ describe('ReactErrorBoundaries', () => {
{getAMixOfNormalAndBrokenRenderElements()}
,
- container
+ container,
);
expect(container.textContent).toBe('Caught an error: Hello.');
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
// The tests below implement new features in Fiber.
@@ -1869,7 +1878,7 @@ describe('ReactErrorBoundaries', () => {
statefulInst = inst} />
,
- container
+ container,
);
log.length = 0;
@@ -1888,9 +1897,7 @@ describe('ReactErrorBoundaries', () => {
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('catches errors in componentDidMount', () => {
@@ -1903,7 +1910,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(log).toEqual([
'ErrorBoundary constructor',
@@ -1945,9 +1952,7 @@ describe('ReactErrorBoundaries', () => {
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('catches errors in componentDidUpdate', () => {
@@ -1956,7 +1961,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
log.length = 0;
@@ -1964,7 +1969,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(log).toEqual([
'ErrorBoundary componentWillReceiveProps',
@@ -1986,9 +1991,7 @@ describe('ReactErrorBoundaries', () => {
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('propagates errors inside boundary during componentDidMount', () => {
@@ -2000,9 +2003,10 @@ describe('ReactErrorBoundaries', () => {
We should never catch our own error: {error.message}.
- )} />
+ )}
+ />
,
- container
+ container,
);
expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
expect(log).toEqual([
@@ -2026,9 +2030,7 @@ describe('ReactErrorBoundaries', () => {
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'ErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['ErrorBoundary componentWillUnmount']);
});
it('lets different boundaries catch their own first errors', () => {
@@ -2042,33 +2044,41 @@ describe('ReactErrorBoundaries', () => {
var container = document.createElement('div');
ReactDOM.render(
-
+
-
+
,
- container
+ container,
);
log.length = 0;
ReactDOM.render(
-
-
+
+
,
- container
+ container,
);
expect(container.firstChild.textContent).toBe(
- 'Caught an unmounting error: E1.' +
- 'Caught an updating error: E3.'
+ 'Caught an unmounting error: E1.' + 'Caught an updating error: E3.',
);
expect(log).toEqual([
// Begin update phase
@@ -2156,7 +2166,7 @@ describe('ReactErrorBoundaries', () => {
,
- container
+ container,
);
expect(container.firstChild.textContent).toBe('Sibling');
expect(log).toEqual([
@@ -2174,9 +2184,7 @@ describe('ReactErrorBoundaries', () => {
log.length = 0;
ReactDOM.unmountComponentAtNode(container);
- expect(log).toEqual([
- 'NoopErrorBoundary componentWillUnmount',
- ]);
+ expect(log).toEqual(['NoopErrorBoundary componentWillUnmount']);
});
it('passes first error when two errors happen in commit', () => {
@@ -2213,13 +2221,9 @@ describe('ReactErrorBoundaries', () => {
caughtError = e;
}
- expect(errors).toEqual([
- 'child sad',
- 'parent sad',
- ]);
+ expect(errors).toEqual(['child sad', 'parent sad']);
// Error should be the first thrown
expect(caughtError.message).toBe('child sad');
});
}
-
});
diff --git a/src/renderers/__tests__/ReactHostOperationHistoryHook-test.js b/src/renderers/__tests__/ReactHostOperationHistoryHook-test.js
index d6c12a6f4c..b787fa13f5 100644
--- a/src/renderers/__tests__/ReactHostOperationHistoryHook-test.js
+++ b/src/renderers/__tests__/ReactHostOperationHistoryHook-test.js
@@ -51,13 +51,15 @@ describeStack('ReactHostOperationHistoryHook', () => {
ReactDOM.render(
, node);
var inst = ReactDOMComponentTree.getInstanceFromNode(node.firstChild);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'mount',
- payload: ReactDOMFeatureFlags.useCreateElement ?
- 'DIV' :
- '
',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'mount',
+ payload: ReactDOMFeatureFlags.useCreateElement
+ ? 'DIV'
+ : '
',
+ },
+ ]);
});
it('gets recorded for composite roots', () => {
@@ -70,14 +72,16 @@ describeStack('ReactHostOperationHistoryHook', () => {
ReactDOM.render(
, node);
var inst = ReactDOMComponentTree.getInstanceFromNode(node.firstChild);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'mount',
- payload: ReactDOMFeatureFlags.useCreateElement ?
- 'DIV' :
- '
',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'mount',
+ payload: ReactDOMFeatureFlags.useCreateElement
+ ? 'DIV'
+ : '
',
+ },
+ ]);
});
it('gets ignored for composite roots that return null', () => {
@@ -111,11 +115,13 @@ describeStack('ReactHostOperationHistoryHook', () => {
// Since empty components should be invisible to hooks,
// we record a "mount" event rather than a "replace with".
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'mount',
- payload: 'SPAN',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'mount',
+ payload: 'SPAN',
+ },
+ ]);
});
});
@@ -124,32 +130,42 @@ describeStack('ReactHostOperationHistoryHook', () => {
var node = document.createElement('div');
ReactHostOperationHistoryHook._preventClearing = true;
- ReactDOM.render(
, node);
+ ReactDOM.render(
+
,
+ node,
+ );
var inst = ReactDOMComponentTree.getInstanceFromNode(node.firstChild);
if (ReactDOMFeatureFlags.useCreateElement) {
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'update styles',
- payload: {
- color: 'red',
- backgroundColor: 'yellow',
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'update styles',
+ payload: {
+ color: 'red',
+ backgroundColor: 'yellow',
+ },
},
- }, {
- instanceID: inst._debugID,
- type: 'mount',
- payload: 'DIV',
- }]);
+ {
+ instanceID: inst._debugID,
+ type: 'mount',
+ payload: 'DIV',
+ },
+ ]);
} else {
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'mount',
- payload: '
',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'mount',
+ payload: '
',
+ },
+ ]);
}
});
@@ -159,31 +175,41 @@ describeStack('ReactHostOperationHistoryHook', () => {
var inst = ReactDOMComponentTree.getInstanceFromNode(node.firstChild);
ReactHostOperationHistoryHook._preventClearing = true;
- ReactDOM.render(
, node);
- ReactDOM.render(
, node);
- ReactDOM.render(
, node);
+ ReactDOM.render(
, node);
+ ReactDOM.render(
+
,
+ node,
+ );
+ ReactDOM.render(
, node);
ReactDOM.render(
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'update styles',
- payload: { color: 'red' },
- }, {
- instanceID: inst._debugID,
- type: 'update styles',
- payload: { color: 'blue', backgroundColor: 'yellow' },
- }, {
- instanceID: inst._debugID,
- type: 'update styles',
- payload: { color: '', backgroundColor: 'green' },
- }, {
- instanceID: inst._debugID,
- type: 'update styles',
- payload: { backgroundColor: '' },
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'update styles',
+ payload: {color: 'red'},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update styles',
+ payload: {color: 'blue', backgroundColor: 'yellow'},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update styles',
+ payload: {color: '', backgroundColor: 'green'},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update styles',
+ payload: {backgroundColor: ''},
+ },
+ ]);
});
it('gets ignored if the styles are shallowly equal', () => {
@@ -192,23 +218,35 @@ describeStack('ReactHostOperationHistoryHook', () => {
var inst = ReactDOMComponentTree.getInstanceFromNode(node.firstChild);
ReactHostOperationHistoryHook._preventClearing = true;
- ReactDOM.render(
, node);
- ReactDOM.render(
, node);
+ ReactDOM.render(
+
,
+ node,
+ );
+ ReactDOM.render(
+
,
+ node,
+ );
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'update styles',
- payload: {
- color: 'red',
- backgroundColor: 'yellow',
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'update styles',
+ payload: {
+ color: 'red',
+ backgroundColor: 'yellow',
+ },
},
- }]);
+ ]);
});
});
@@ -222,26 +260,32 @@ describeStack('ReactHostOperationHistoryHook', () => {
var inst = ReactDOMComponentTree.getInstanceFromNode(node.firstChild);
if (ReactDOMFeatureFlags.useCreateElement) {
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { className: 'rad' },
- }, {
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { tabIndex: 42 },
- }, {
- instanceID: inst._debugID,
- type: 'mount',
- payload: 'DIV',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {className: 'rad'},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {tabIndex: 42},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'mount',
+ payload: 'DIV',
+ },
+ ]);
} else {
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'mount',
- payload: '
',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'mount',
+ payload: '
',
+ },
+ ]);
}
});
@@ -255,27 +299,33 @@ describeStack('ReactHostOperationHistoryHook', () => {
ReactDOM.render(
, node);
ReactDOM.render(
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { className: 'rad' },
- }, {
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { className: 'mad' },
- }, {
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { tabIndex: 42 },
- }, {
- instanceID: inst._debugID,
- type: 'remove attribute',
- payload: 'className',
- }, {
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { tabIndex: 43 },
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {className: 'rad'},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {className: 'mad'},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {tabIndex: 42},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'remove attribute',
+ payload: 'className',
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {tabIndex: 43},
+ },
+ ]);
});
});
@@ -289,15 +339,18 @@ describeStack('ReactHostOperationHistoryHook', () => {
ReactDOM.render(
, node);
ReactDOM.render(
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { disabled: true },
- }, {
- instanceID: inst._debugID,
- type: 'remove attribute',
- payload: 'disabled',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {disabled: true},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'remove attribute',
+ payload: 'disabled',
+ },
+ ]);
});
});
@@ -310,26 +363,32 @@ describeStack('ReactHostOperationHistoryHook', () => {
var inst = ReactDOMComponentTree.getInstanceFromNode(node.firstChild);
if (ReactDOMFeatureFlags.useCreateElement) {
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { 'data-x': 'rad' },
- }, {
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { 'data-y': 42 },
- }, {
- instanceID: inst._debugID,
- type: 'mount',
- payload: 'DIV',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {'data-x': 'rad'},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {'data-y': 42},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'mount',
+ payload: 'DIV',
+ },
+ ]);
} else {
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'mount',
- payload: '
',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'mount',
+ payload: '
',
+ },
+ ]);
}
});
@@ -343,27 +402,33 @@ describeStack('ReactHostOperationHistoryHook', () => {
ReactDOM.render(
, node);
ReactDOM.render(
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { 'data-x': 'rad' },
- }, {
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { 'data-x': 'mad' },
- }, {
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { 'data-y': 42 },
- }, {
- instanceID: inst._debugID,
- type: 'remove attribute',
- payload: 'data-x',
- }, {
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { 'data-y': 43 },
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {'data-x': 'rad'},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {'data-x': 'mad'},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {'data-y': 42},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'remove attribute',
+ payload: 'data-x',
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {'data-y': 43},
+ },
+ ]);
});
});
@@ -376,26 +441,32 @@ describeStack('ReactHostOperationHistoryHook', () => {
var inst = ReactDOMComponentTree.getInstanceFromNode(node.firstChild);
if (ReactDOMFeatureFlags.useCreateElement) {
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { className: 'rad' },
- }, {
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { tabIndex: 42 },
- }, {
- instanceID: inst._debugID,
- type: 'mount',
- payload: 'MY-COMPONENT',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {className: 'rad'},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {tabIndex: 42},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'mount',
+ payload: 'MY-COMPONENT',
+ },
+ ]);
} else {
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'mount',
- payload: '
',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'mount',
+ payload: '
',
+ },
+ ]);
}
});
@@ -409,27 +480,33 @@ describeStack('ReactHostOperationHistoryHook', () => {
ReactDOM.render(
, node);
ReactDOM.render(
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { className: 'rad' },
- }, {
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { className: 'mad' },
- }, {
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { tabIndex: 42 },
- }, {
- instanceID: inst._debugID,
- type: 'remove attribute',
- payload: 'className',
- }, {
- instanceID: inst._debugID,
- type: 'update attribute',
- payload: { tabIndex: 43 },
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {className: 'rad'},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {className: 'mad'},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {tabIndex: 42},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'remove attribute',
+ payload: 'className',
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'update attribute',
+ payload: {tabIndex: 43},
+ },
+ ]);
});
});
});
@@ -444,26 +521,33 @@ describeStack('ReactHostOperationHistoryHook', () => {
ReactHostOperationHistoryHook._preventClearing = true;
ReactDOM.render(
Bye.
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'replace text',
- payload: 'Bye.',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'replace text',
+ payload: 'Bye.',
+ },
+ ]);
});
it('gets recorded during an update from html', () => {
var node = document.createElement('div');
- ReactDOM.render(
, node);
+ ReactDOM.render(
+
,
+ node,
+ );
var inst = ReactDOMComponentTree.getInstanceFromNode(node.firstChild);
ReactHostOperationHistoryHook._preventClearing = true;
ReactDOM.render(
Bye.
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'replace text',
- payload: 'Bye.',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'replace text',
+ payload: 'Bye.',
+ },
+ ]);
});
it('gets recorded during an update from children', () => {
@@ -474,19 +558,23 @@ describeStack('ReactHostOperationHistoryHook', () => {
ReactHostOperationHistoryHook._preventClearing = true;
ReactDOM.render(
Bye.
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'remove child',
- payload: {fromIndex: 0},
- }, {
- instanceID: inst._debugID,
- type: 'remove child',
- payload: {fromIndex: 1},
- }, {
- instanceID: inst._debugID,
- type: 'replace text',
- payload: 'Bye.',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'remove child',
+ payload: {fromIndex: 0},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'remove child',
+ payload: {fromIndex: 1},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'replace text',
+ payload: 'Bye.',
+ },
+ ]);
});
it('gets ignored if new text is equal', () => {
@@ -504,21 +592,28 @@ describeStack('ReactHostOperationHistoryHook', () => {
it('gets recorded during an update', () => {
var node = document.createElement('div');
ReactDOM.render(
{'Hi.'}{42}
, node);
- var inst1 = ReactDOMComponentTree.getInstanceFromNode(node.firstChild.childNodes[0]);
- var inst2 = ReactDOMComponentTree.getInstanceFromNode(node.firstChild.childNodes[3]);
+ var inst1 = ReactDOMComponentTree.getInstanceFromNode(
+ node.firstChild.childNodes[0],
+ );
+ var inst2 = ReactDOMComponentTree.getInstanceFromNode(
+ node.firstChild.childNodes[3],
+ );
ReactHostOperationHistoryHook._preventClearing = true;
ReactDOM.render(
{'Bye.'}{43}
, node);
- assertHistoryMatches([{
- instanceID: inst1._debugID,
- type: 'replace text',
- payload: 'Bye.',
- }, {
- instanceID: inst2._debugID,
- type: 'replace text',
- payload: '43',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst1._debugID,
+ type: 'replace text',
+ payload: 'Bye.',
+ },
+ {
+ instanceID: inst2._debugID,
+ type: 'replace text',
+ payload: '43',
+ },
+ ]);
});
it('gets ignored if new text is equal', () => {
@@ -550,11 +645,13 @@ describeStack('ReactHostOperationHistoryHook', () => {
ReactHostOperationHistoryHook._preventClearing = true;
ReactDOM.render(
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'replace with',
- payload: 'SPAN',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'replace with',
+ payload: 'SPAN',
+ },
+ ]);
});
it('gets recorded when composite renders to null after a native', () => {
@@ -573,11 +670,13 @@ describeStack('ReactHostOperationHistoryHook', () => {
ReactHostOperationHistoryHook._preventClearing = true;
ReactDOM.render(
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'replace with',
- payload: '#comment',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'replace with',
+ payload: '#comment',
+ },
+ ]);
});
it('gets ignored if the type has not changed', () => {
@@ -606,37 +705,32 @@ describeStack('ReactHostOperationHistoryHook', () => {
var inst = ReactDOMComponentTree.getInstanceFromNode(node.firstChild);
ReactHostOperationHistoryHook._preventClearing = true;
- ReactDOM.render(
-
,
- node
- );
+ ReactDOM.render(
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'replace children',
- payload: 'Bye.',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'replace children',
+ payload: 'Bye.',
+ },
+ ]);
});
it('gets recorded during an update from html', () => {
var node = document.createElement('div');
- ReactDOM.render(
-
,
- node
- );
+ ReactDOM.render(
, node);
var inst = ReactDOMComponentTree.getInstanceFromNode(node.firstChild);
ReactHostOperationHistoryHook._preventClearing = true;
- ReactDOM.render(
-
,
- node
- );
+ ReactDOM.render(
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'replace children',
- payload: 'Bye.',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'replace children',
+ payload: 'Bye.',
+ },
+ ]);
});
it('gets recorded during an update from children', () => {
@@ -645,38 +739,33 @@ describeStack('ReactHostOperationHistoryHook', () => {
var inst = ReactDOMComponentTree.getInstanceFromNode(node.firstChild);
ReactHostOperationHistoryHook._preventClearing = true;
- ReactDOM.render(
-
,
- node
- );
+ ReactDOM.render(
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'remove child',
- payload: {fromIndex: 0},
- }, {
- instanceID: inst._debugID,
- type: 'remove child',
- payload: {fromIndex: 1},
- }, {
- instanceID: inst._debugID,
- type: 'replace children',
- payload: 'Hi.',
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'remove child',
+ payload: {fromIndex: 0},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'remove child',
+ payload: {fromIndex: 1},
+ },
+ {
+ instanceID: inst._debugID,
+ type: 'replace children',
+ payload: 'Hi.',
+ },
+ ]);
});
it('gets ignored if new html is equal', () => {
var node = document.createElement('div');
- ReactDOM.render(
-
,
- node
- );
+ ReactDOM.render(
, node);
ReactHostOperationHistoryHook._preventClearing = true;
- ReactDOM.render(
-
,
- node
- );
+ ReactDOM.render(
, node);
assertHistoryMatches([]);
});
@@ -691,11 +780,13 @@ describeStack('ReactHostOperationHistoryHook', () => {
ReactHostOperationHistoryHook._preventClearing = true;
ReactDOM.render(
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'insert child',
- payload: {toIndex: 1, content: 'P'},
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'insert child',
+ payload: {toIndex: 1, content: 'P'},
+ },
+ ]);
});
});
@@ -708,11 +799,13 @@ describeStack('ReactHostOperationHistoryHook', () => {
ReactHostOperationHistoryHook._preventClearing = true;
ReactDOM.render(
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'move child',
- payload: {fromIndex: 0, toIndex: 1},
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'move child',
+ payload: {fromIndex: 0, toIndex: 1},
+ },
+ ]);
});
});
@@ -725,11 +818,13 @@ describeStack('ReactHostOperationHistoryHook', () => {
ReactHostOperationHistoryHook._preventClearing = true;
ReactDOM.render(
, node);
- assertHistoryMatches([{
- instanceID: inst._debugID,
- type: 'remove child',
- payload: {fromIndex: 1},
- }]);
+ assertHistoryMatches([
+ {
+ instanceID: inst._debugID,
+ type: 'remove child',
+ payload: {fromIndex: 1},
+ },
+ ]);
});
});
});
diff --git a/src/renderers/__tests__/ReactIdentity-test.js b/src/renderers/__tests__/ReactIdentity-test.js
index bb82a9d611..e25f1ff049 100644
--- a/src/renderers/__tests__/ReactIdentity-test.js
+++ b/src/renderers/__tests__/ReactIdentity-test.js
@@ -17,7 +17,6 @@ var ReactFragment;
var ReactTestUtils;
describe('ReactIdentity', () => {
-
beforeEach(() => {
jest.resetModules();
React = require('react');
@@ -32,11 +31,12 @@ describe('ReactIdentity', () => {
it('should allow key property to express identity', () => {
var node;
- var Component = (props) =>
-
node = c}>
+ var Component = props => (
+
;
+
+ );
var container = document.createElement('div');
ReactDOM.render(
, container);
@@ -58,12 +58,12 @@ describe('ReactIdentity', () => {
var node1;
var node2;
ReactDOM.render(
-
node1 = c} />,
- container
+
node1 = c} />,
+ container,
);
ReactDOM.render(
-
node2 = c} />,
- container
+
node2 = c} />,
+ container,
);
expect(node1).not.toBe(node2);
@@ -91,10 +91,7 @@ describe('ReactIdentity', () => {
it('should allow any character as a key, in a detached parent', () => {
var detachedContainer = document.createElement('div');
- renderAComponentWithKeyIntoContainer(
- "<'WEIRD/&\\key'>",
- detachedContainer
- );
+ renderAComponentWithKeyIntoContainer("<'WEIRD/&\\key'>", detachedContainer);
});
it('should allow any character as a key, in an attached parent', () => {
@@ -103,17 +100,13 @@ describe('ReactIdentity', () => {
var attachedContainer = document.createElement('div');
document.body.appendChild(attachedContainer);
- renderAComponentWithKeyIntoContainer(
- "<'WEIRD/&\\key'>",
- attachedContainer
- );
+ renderAComponentWithKeyIntoContainer("<'WEIRD/&\\key'>", attachedContainer);
document.body.removeChild(attachedContainer);
});
it('should not allow scripts in keys to execute', () => {
- var h4x0rKey =
- '">
;
+
+ );
expect(function() {
ReactTestUtils.renderIntoDocument(component);
}).not.toThrow();
});
-
-
});
diff --git a/src/renderers/__tests__/ReactMockedComponent-test.js b/src/renderers/__tests__/ReactMockedComponent-test.js
index bb924cfbe2..38083e4f9c 100644
--- a/src/renderers/__tests__/ReactMockedComponent-test.js
+++ b/src/renderers/__tests__/ReactMockedComponent-test.js
@@ -18,13 +18,16 @@ var AutoMockedComponent;
var MockedComponent;
describe('ReactMockedComponent', () => {
-
beforeEach(() => {
React = require('react');
ReactTestUtils = require('ReactTestUtils');
- AutoMockedComponent = jest.genMockFromModule('ReactMockedComponentTestComponent');
- MockedComponent = jest.genMockFromModule('ReactMockedComponentTestComponent');
+ AutoMockedComponent = jest.genMockFromModule(
+ 'ReactMockedComponentTestComponent',
+ );
+ MockedComponent = jest.genMockFromModule(
+ 'ReactMockedComponentTestComponent',
+ );
ReactTestUtils.mockComponent(MockedComponent);
});
@@ -52,7 +55,7 @@ describe('ReactMockedComponent', () => {
var found = ReactTestUtils.findRenderedComponentWithType(
instance,
- AutoMockedComponent
+ AutoMockedComponent,
);
expect(typeof found).toBe('object');
@@ -85,7 +88,7 @@ describe('ReactMockedComponent', () => {
var found = ReactTestUtils.findRenderedComponentWithType(
instance,
- MockedComponent
+ MockedComponent,
);
expect(typeof found).toBe('object');
@@ -96,5 +99,4 @@ describe('ReactMockedComponent', () => {
var instance = ReactTestUtils.renderIntoDocument(
);
expect(typeof instance.hasCustomMethod).toBe('function');
});
-
});
diff --git a/src/renderers/__tests__/ReactMultiChild-test.js b/src/renderers/__tests__/ReactMultiChild-test.js
index 3fee4e0915..2a78651a4d 100644
--- a/src/renderers/__tests__/ReactMultiChild-test.js
+++ b/src/renderers/__tests__/ReactMultiChild-test.js
@@ -119,7 +119,7 @@ describe('ReactMultiChild', () => {
ReactDOM.render(
,
- container
+ container,
);
expect(mockMount.mock.calls.length).toBe(1);
@@ -177,25 +177,24 @@ describe('ReactMultiChild', () => {
}
}
- ReactDOM.render(
-
,
- container
+ container,
);
expectDev(console.error.calls.count()).toBe(1);
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toContain(
+ expectDev(
+ normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]),
+ ).toContain(
'Encountered two children with the same key, `1`. ' +
- 'Child keys must be unique; when two children share a key, ' +
- 'only the first child will be used.\n' +
- ' in div (at **)\n' +
- ' in WrapperComponent (at **)\n' +
- ' in div (at **)\n' +
- ' in Parent (at **)'
+ 'Child keys must be unique; when two children share a key, ' +
+ 'only the first child will be used.\n' +
+ ' in div (at **)\n' +
+ ' in WrapperComponent (at **)\n' +
+ ' in div (at **)\n' +
+ ' in Parent (at **)',
);
});
@@ -242,23 +241,25 @@ describe('ReactMultiChild', () => {
ReactDOM.render(
,
- container
+ container,
);
ReactDOM.render(
,
- container
+ container,
);
expectDev(console.error.calls.count()).toBe(1);
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toContain(
+ expectDev(
+ normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]),
+ ).toContain(
'Encountered two children with the same key, `1`. ' +
- 'Child keys must be unique; when two children share a key, ' +
- 'only the first child will be used.\n' +
- ' in div (at **)\n' +
- ' in WrapperComponent (at **)\n' +
- ' in div (at **)\n' +
- ' in Parent (at **)'
+ 'Child keys must be unique; when two children share a key, ' +
+ 'only the first child will be used.\n' +
+ ' in div (at **)\n' +
+ ' in WrapperComponent (at **)\n' +
+ ' in div (at **)\n' +
+ ' in Parent (at **)',
);
});
});
@@ -267,9 +268,7 @@ describe('ReactMultiChild', () => {
spyOn(console, 'error');
class Parent extends React.Component {
render() {
- return (
-
;
}
}
var container = document.createElement('div');
@@ -277,8 +276,8 @@ describe('ReactMultiChild', () => {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Using Maps as children is unsupported and will likely yield ' +
- 'unexpected results. Convert it to a sequence/iterable of keyed ' +
- 'ReactElements instead.\n\nCheck the render method of `Parent`.'
+ 'unexpected results. Convert it to a sequence/iterable of keyed ' +
+ 'ReactElements instead.\n\nCheck the render method of `Parent`.',
);
});
@@ -303,7 +302,7 @@ describe('ReactMultiChild', () => {
class Letters extends React.Component {
render() {
const letters = this.props.letters.split('');
- return
;
}
}
@@ -337,8 +336,8 @@ describe('ReactMultiChild', () => {
// These are reference-unequal so they will be swapped even if they have
// matching keys
- var SpyA = (props) =>
;
var container = document.createElement('div');
ReactDOM.render(
@@ -346,14 +345,14 @@ describe('ReactMultiChild', () => {