react: convert var to let/const (#11715)
Raphael Amorim committed
Nov 30, 2017 at 10:08 UTC
3c977dea6b96f6a9bb39f09886848da870748441
21 files changed
+521
-508
packages/react/index.js
+1
-1
@@ -9,7 +9,7 @@
9
10
'use strict';
11
12
-var React = require('./src/React');
12
+const React = require('./src/React');
13
14
// TODO: decide on the top-level export form.
15
// This is hacky but makes it work with both Rollup and Jest.
packages/react/src/React.js
+1
-1
@@ -25,7 +25,7 @@ import {
25
} from './ReactElementValidator';
26
import ReactDebugCurrentFrame from './ReactDebugCurrentFrame';
27
28
-var React = {
28
+const React = {
29
Children: {
30
map,
31
forEach,
packages/react/src/ReactBaseClasses.js
+5
-5
@@ -85,7 +85,7 @@ Component.prototype.forceUpdate = function(callback) {
85
* modern base class. Instead, we define a getter that warns if it's accessed.
86
*/
87
if (__DEV__) {
88
- var deprecatedAPIs = {
88
+ const deprecatedAPIs = {
89
isMounted: [
90
'isMounted',
91
'Instead, make sure to clean up subscriptions and pending requests in ' +
@@ -97,7 +97,7 @@ if (__DEV__) {
97
'https://github.com/facebook/react/issues/3236).',
98
],
99
};
100
- var defineDeprecationWarning = function(methodName, info) {
100
+ const defineDeprecationWarning = function(methodName, info) {
101
Object.defineProperty(Component.prototype, methodName, {
102
get: function() {
103
lowPriorityWarning(
@@ -110,7 +110,7 @@ if (__DEV__) {
110
},
111
});
112
};
113
- for (var fnName in deprecatedAPIs) {
113
+ for (const fnName in deprecatedAPIs) {
114
if (deprecatedAPIs.hasOwnProperty(fnName)) {
115
defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
116
}
@@ -132,7 +132,7 @@ function PureComponent(props, context, updater) {
132
133
function ComponentDummy() {}
134
ComponentDummy.prototype = Component.prototype;
135
-var pureComponentPrototype = (PureComponent.prototype = new ComponentDummy());
135
+const pureComponentPrototype = (PureComponent.prototype = new ComponentDummy());
136
pureComponentPrototype.constructor = PureComponent;
137
// Avoid an extra prototype jump for these methods.
138
Object.assign(pureComponentPrototype, Component.prototype);
@@ -148,7 +148,7 @@ function AsyncComponent(props, context, updater) {
148
this.updater = updater || ReactNoopUpdateQueue;
149
}
150
151
-var asyncComponentPrototype = (AsyncComponent.prototype = new ComponentDummy());
151
+const asyncComponentPrototype = (AsyncComponent.prototype = new ComponentDummy());
152
asyncComponentPrototype.constructor = AsyncComponent;
153
// Avoid an extra prototype jump for these methods.
154
Object.assign(asyncComponentPrototype, Component.prototype);
packages/react/src/ReactChildren.js
+31
-30
@@ -19,8 +19,8 @@ import {
19
import {isValidElement, cloneAndReplaceKey} from './ReactElement';
20
import ReactDebugCurrentFrame from './ReactDebugCurrentFrame';
21
22
-var SEPARATOR = '.';
23
-var SUBSEPARATOR = ':';
22
+const SEPARATOR = '.';
23
+const SUBSEPARATOR = ':';
24
25
/**
26
* Escape and wrap key so it is safe to use as a reactid
@@ -29,12 +29,12 @@ var SUBSEPARATOR = ':';
29
* @return {string} the escaped key.
30
*/
31
function escape(key) {
32
- var escapeRegex = /[=:]/g;
33
- var escaperLookup = {
32
+ const escapeRegex = /[=:]/g;
33
+ const escaperLookup = {
34
'=': '=0',
35
':': '=2',
36
};
37
- var escapedString = ('' + key).replace(escapeRegex, function(match) {
37
+ const escapedString = ('' + key).replace(escapeRegex, function(match) {
38
return escaperLookup[match];
39
});
40
@@ -46,15 +46,15 @@ function escape(key) {
46
* pattern.
47
*/
48
49
-var didWarnAboutMaps = false;
49
+let didWarnAboutMaps = false;
50
51
-var userProvidedKeyEscapeRegex = /\/+/g;
51
+const userProvidedKeyEscapeRegex = /\/+/g;
52
function escapeUserProvidedKey(text) {
53
return ('' + text).replace(userProvidedKeyEscapeRegex, '$&/');
54
}
55
56
-var POOL_SIZE = 10;
57
-var traverseContextPool = [];
56
+const POOL_SIZE = 10;
57
+const traverseContextPool = [];
58
function getPooledTraverseContext(
59
mapResult,
60
keyPrefix,
@@ -62,7 +62,7 @@ function getPooledTraverseContext(
62
mapContext,
63
) {
64
if (traverseContextPool.length) {
65
- var traverseContext = traverseContextPool.pop();
65
+ const traverseContext = traverseContextPool.pop();
66
traverseContext.result = mapResult;
67
traverseContext.keyPrefix = keyPrefix;
68
traverseContext.func = mapFunction;
@@ -105,7 +105,7 @@ function traverseAllChildrenImpl(
105
callback,
106
traverseContext,
107
) {
108
- var type = typeof children;
108
+ const type = typeof children;
109
110
if (type === 'undefined' || type === 'boolean') {
111
// All of the above are perceived as null.
@@ -144,13 +144,14 @@ function traverseAllChildrenImpl(
144
return 1;
145
}
146
147
- var child;
148
- var nextName;
149
- var subtreeCount = 0; // Count of children found in the current subtree.
150
- var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
147
+ let child;
148
+ let nextName;
149
+ let subtreeCount = 0; // Count of children found in the current subtree.
150
+ const nextNamePrefix =
151
+ nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
152
153
if (Array.isArray(children)) {
153
- for (var i = 0; i < children.length; i++) {
154
+ for (let i = 0; i < children.length; i++) {
155
child = children[i];
156
nextName = nextNamePrefix + getComponentKey(child, i);
157
subtreeCount += traverseAllChildrenImpl(
@@ -161,7 +162,7 @@ function traverseAllChildrenImpl(
162
);
163
}
164
} else {
164
- var iteratorFn = getIteratorFn(children);
165
+ const iteratorFn = getIteratorFn(children);
166
if (typeof iteratorFn === 'function') {
167
if (__DEV__) {
168
// Warn about using Maps as children
@@ -177,9 +178,9 @@ function traverseAllChildrenImpl(
178
}
179
}
180
180
- var iterator = iteratorFn.call(children);
181
- var step;
182
- var ii = 0;
181
+ const iterator = iteratorFn.call(children);
182
+ let step;
183
+ let ii = 0;
184
while (!(step = iterator.next()).done) {
185
child = step.value;
186
nextName = nextNamePrefix + getComponentKey(child, ii++);
@@ -191,14 +192,14 @@ function traverseAllChildrenImpl(
192
);
193
}
194
} else if (type === 'object') {
194
- var addendum = '';
195
+ let addendum = '';
196
if (__DEV__) {
197
addendum =
198
' If you meant to render a collection of children, use an array ' +
199
'instead.' +
200
ReactDebugCurrentFrame.getStackAddendum();
201
}
201
- var childrenString = '' + children;
202
+ const childrenString = '' + children;
203
invariant(
204
false,
205
'Objects are not valid as a React child (found: %s).%s',
@@ -260,7 +261,7 @@ function getComponentKey(component, index) {
261
}
262
263
function forEachSingleChild(bookKeeping, child, name) {
263
- var {func, context} = bookKeeping;
264
+ const {func, context} = bookKeeping;
265
func.call(context, child, bookKeeping.count++);
266
}
267
@@ -280,7 +281,7 @@ function forEachChildren(children, forEachFunc, forEachContext) {
281
if (children == null) {
282
return children;
283
}
283
- var traverseContext = getPooledTraverseContext(
284
+ const traverseContext = getPooledTraverseContext(
285
null,
286
null,
287
forEachFunc,
@@ -291,9 +292,9 @@ function forEachChildren(children, forEachFunc, forEachContext) {
292
}
293
294
function mapSingleChildIntoContext(bookKeeping, child, childKey) {
294
- var {result, keyPrefix, func, context} = bookKeeping;
295
+ const {result, keyPrefix, func, context} = bookKeeping;
296
296
- var mappedChild = func.call(context, child, bookKeeping.count++);
297
+ let mappedChild = func.call(context, child, bookKeeping.count++);
298
if (Array.isArray(mappedChild)) {
299
mapIntoWithKeyPrefixInternal(
300
mappedChild,
@@ -319,11 +320,11 @@ function mapSingleChildIntoContext(bookKeeping, child, childKey) {
320
}
321
322
function mapIntoWithKeyPrefixInternal(children, array, prefix, func, context) {
322
- var escapedPrefix = '';
323
+ let escapedPrefix = '';
324
if (prefix != null) {
325
escapedPrefix = escapeUserProvidedKey(prefix) + '/';
326
}
326
- var traverseContext = getPooledTraverseContext(
327
+ const traverseContext = getPooledTraverseContext(
328
array,
329
escapedPrefix,
330
func,
@@ -350,7 +351,7 @@ function mapChildren(children, func, context) {
351
if (children == null) {
352
return children;
353
}
353
- var result = [];
354
+ const result = [];
355
mapIntoWithKeyPrefixInternal(children, result, null, func, context);
356
return result;
357
}
@@ -375,7 +376,7 @@ function countChildren(children, context) {
376
* See https://reactjs.org/docs/react-api.html#react.children.toarray
377
*/
378
function toArray(children) {
378
- var result = [];
379
+ const result = [];
380
mapIntoWithKeyPrefixInternal(
381
children,
382
result,
packages/react/src/ReactCurrentOwner.js
+1
-1
@@ -15,7 +15,7 @@ import type {Fiber} from 'react-reconciler/src/ReactFiber';
15
* The current owner is the component who should own any components that are
16
* currently being constructed.
17
*/
18
-var ReactCurrentOwner = {
18
+const ReactCurrentOwner = {
19
/**
20
* @internal
21
* @type {ReactComponent}
packages/react/src/ReactElement.js
+33
-33
@@ -10,21 +10,21 @@ import {REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
10
11
import ReactCurrentOwner from './ReactCurrentOwner';
12
13
-var hasOwnProperty = Object.prototype.hasOwnProperty;
13
+const hasOwnProperty = Object.prototype.hasOwnProperty;
14
15
-var RESERVED_PROPS = {
15
+const RESERVED_PROPS = {
16
key: true,
17
ref: true,
18
__self: true,
19
__source: true,
20
};
21
22
-var specialPropKeyWarningShown, specialPropRefWarningShown;
22
+let specialPropKeyWarningShown, specialPropRefWarningShown;
23
24
function hasValidRef(config) {
25
if (__DEV__) {
26
if (hasOwnProperty.call(config, 'ref')) {
27
- var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
27
+ const getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
28
if (getter && getter.isReactWarning) {
29
return false;
30
}
@@ -36,7 +36,7 @@ function hasValidRef(config) {
36
function hasValidKey(config) {
37
if (__DEV__) {
38
if (hasOwnProperty.call(config, 'key')) {
39
- var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
39
+ const getter = Object.getOwnPropertyDescriptor(config, 'key').get;
40
if (getter && getter.isReactWarning) {
41
return false;
42
}
@@ -46,7 +46,7 @@ function hasValidKey(config) {
46
}
47
48
function defineKeyPropWarningGetter(props, displayName) {
49
- var warnAboutAccessingKey = function() {
49
+ const warnAboutAccessingKey = function() {
50
if (!specialPropKeyWarningShown) {
51
specialPropKeyWarningShown = true;
52
warning(
@@ -67,7 +67,7 @@ function defineKeyPropWarningGetter(props, displayName) {
67
}
68
69
function defineRefPropWarningGetter(props, displayName) {
70
- var warnAboutAccessingRef = function() {
70
+ const warnAboutAccessingRef = function() {
71
if (!specialPropRefWarningShown) {
72
specialPropRefWarningShown = true;
73
warning(
@@ -107,8 +107,8 @@ function defineRefPropWarningGetter(props, displayName) {
107
* @param {*} props
108
* @internal
109
*/
110
-var ReactElement = function(type, key, ref, self, source, owner, props) {
111
- var element = {
110
+const ReactElement = function(type, key, ref, self, source, owner, props) {
111
+ const element = {
112
// This tag allow us to uniquely identify this as a React Element
113
$$typeof: REACT_ELEMENT_TYPE,
114
@@ -168,15 +168,15 @@ var ReactElement = function(type, key, ref, self, source, owner, props) {
168
* See https://reactjs.org/docs/react-api.html#createelement
169
*/
170
export function createElement(type, config, children) {
171
- var propName;
171
+ let propName;
172
173
// Reserved names are extracted
174
- var props = {};
174
+ const props = {};
175
176
- var key = null;
177
- var ref = null;
178
- var self = null;
179
- var source = null;
176
+ let key = null;
177
+ let ref = null;
178
+ let self = null;
179
+ let source = null;
180
181
if (config != null) {
182
if (hasValidRef(config)) {
@@ -201,12 +201,12 @@ export function createElement(type, config, children) {
201
202
// Children can be more than one argument, and those are transferred onto
203
// the newly allocated props object.
204
- var childrenLength = arguments.length - 2;
204
+ const childrenLength = arguments.length - 2;
205
if (childrenLength === 1) {
206
props.children = children;
207
} else if (childrenLength > 1) {
208
- var childArray = Array(childrenLength);
209
- for (var i = 0; i < childrenLength; i++) {
208
+ const childArray = Array(childrenLength);
209
+ for (let i = 0; i < childrenLength; i++) {
210
childArray[i] = arguments[i + 2];
211
}
212
if (__DEV__) {
@@ -219,7 +219,7 @@ export function createElement(type, config, children) {
219
220
// Resolve default props
221
if (type && type.defaultProps) {
222
- var defaultProps = type.defaultProps;
222
+ const defaultProps = type.defaultProps;
223
for (propName in defaultProps) {
224
if (props[propName] === undefined) {
225
props[propName] = defaultProps[propName];
@@ -232,7 +232,7 @@ export function createElement(type, config, children) {
232
typeof props.$$typeof === 'undefined' ||
233
props.$$typeof !== REACT_ELEMENT_TYPE
234
) {
235
- var displayName =
235
+ const displayName =
236
typeof type === 'function'
237
? type.displayName || type.name || 'Unknown'
238
: type;
@@ -261,7 +261,7 @@ export function createElement(type, config, children) {
261
* See https://reactjs.org/docs/react-api.html#createfactory
262
*/
263
export function createFactory(type) {
264
- var factory = createElement.bind(null, type);
264
+ const factory = createElement.bind(null, type);
265
// Expose the type on the factory and the prototype so that it can be
266
// easily accessed on elements. E.g. `<Foo />.type === Foo`.
267
// This should not be named `constructor` since this may not be the function
@@ -272,7 +272,7 @@ export function createFactory(type) {
272
}
273
274
export function cloneAndReplaceKey(oldElement, newKey) {
275
- var newElement = ReactElement(
275
+ const newElement = ReactElement(
276
oldElement.type,
277
newKey,
278
oldElement.ref,
@@ -290,23 +290,23 @@ export function cloneAndReplaceKey(oldElement, newKey) {
290
* See https://reactjs.org/docs/react-api.html#cloneelement
291
*/
292
export function cloneElement(element, config, children) {
293
- var propName;
293
+ let propName;
294
295
// Original props are copied
296
- var props = Object.assign({}, element.props);
296
+ const props = Object.assign({}, element.props);
297
298
// Reserved names are extracted
299
- var key = element.key;
300
- var ref = element.ref;
299
+ let key = element.key;
300
+ let ref = element.ref;
301
// Self is preserved since the owner is preserved.
302
- var self = element._self;
302
+ const self = element._self;
303
// Source is preserved since cloneElement is unlikely to be targeted by a
304
// transpiler, and the original source is probably a better indicator of the
305
// true owner.
306
- var source = element._source;
306
+ const source = element._source;
307
308
// Owner will be preserved, unless ref is overridden
309
- var owner = element._owner;
309
+ let owner = element._owner;
310
311
if (config != null) {
312
if (hasValidRef(config)) {
@@ -319,7 +319,7 @@ export function cloneElement(element, config, children) {
319
}
320
321
// Remaining properties override existing props
322
- var defaultProps;
322
+ let defaultProps;
323
if (element.type && element.type.defaultProps) {
324
defaultProps = element.type.defaultProps;
325
}
@@ -340,12 +340,12 @@ export function cloneElement(element, config, children) {
340
341
// Children can be more than one argument, and those are transferred onto
342
// the newly allocated props object.
343
- var childrenLength = arguments.length - 2;
343
+ const childrenLength = arguments.length - 2;
344
if (childrenLength === 1) {
345
props.children = children;
346
} else if (childrenLength > 1) {
347
- var childArray = Array(childrenLength);
348
- for (var i = 0; i < childrenLength; i++) {
347
+ const childArray = Array(childrenLength);
348
+ for (let i = 0; i < childrenLength; i++) {
349
childArray[i] = arguments[i + 2];
350
}
351
props.children = childArray;
packages/react/src/ReactElementValidator.js
+28
-28
@@ -43,10 +43,10 @@ if (__DEV__) {
43
};
44
45
var getStackAddendum = function(): string {
46
- var stack = '';
46
+ let stack = '';
47
if (currentlyValidatingElement) {
48
- var name = getDisplayName(currentlyValidatingElement);
49
- var owner = currentlyValidatingElement._owner;
48
+ const name = getDisplayName(currentlyValidatingElement);
49
+ const owner = currentlyValidatingElement._owner;
50
stack += describeComponentFrame(
51
name,
52
currentlyValidatingElement._source,
@@ -62,7 +62,7 @@ if (__DEV__) {
62
63
function getDeclarationErrorAddendum() {
64
if (ReactCurrentOwner.current) {
65
- var name = getComponentName(ReactCurrentOwner.current);
65
+ const name = getComponentName(ReactCurrentOwner.current);
66
if (name) {
67
return '\n\nCheck the render method of `' + name + '`.';
68
}
@@ -76,9 +76,9 @@ function getSourceInfoErrorAddendum(elementProps) {
76
elementProps !== undefined &&
77
elementProps.__source !== undefined
78
) {
79
- var source = elementProps.__source;
80
- var fileName = source.fileName.replace(/^.*[\\\/]/, '');
81
- var lineNumber = source.lineNumber;
79
+ const source = elementProps.__source;
80
+ const fileName = source.fileName.replace(/^.*[\\\/]/, '');
81
+ const lineNumber = source.lineNumber;
82
return '\n\nCheck your code at ' + fileName + ':' + lineNumber + '.';
83
}
84
return '';
@@ -89,13 +89,13 @@ function getSourceInfoErrorAddendum(elementProps) {
89
* object keys are not valid. This allows us to keep track of children between
90
* updates.
91
*/
92
-var ownerHasKeyUseWarning = {};
92
+const ownerHasKeyUseWarning = {};
93
94
function getCurrentComponentErrorInfo(parentType) {
95
- var info = getDeclarationErrorAddendum();
95
+ let info = getDeclarationErrorAddendum();
96
97
if (!info) {
98
- var parentName =
98
+ const parentName =
99
typeof parentType === 'string'
100
? parentType
101
: parentType.displayName || parentType.name;
@@ -123,7 +123,7 @@ function validateExplicitKey(element, parentType) {
123
}
124
element._store.validated = true;
125
126
- var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
126
+ const currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
127
if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
128
return;
129
}
@@ -132,7 +132,7 @@ function validateExplicitKey(element, parentType) {
132
// Usually the current owner is the offender, but if it accepts children as a
133
// property, it may be the creator of the child that's responsible for
134
// assigning it a key.
135
- var childOwner = '';
135
+ let childOwner = '';
136
if (
137
element &&
138
element._owner &&
@@ -172,8 +172,8 @@ function validateChildKeys(node, parentType) {
172
return;
173
}
174
if (Array.isArray(node)) {
175
- for (var i = 0; i < node.length; i++) {
176
- var child = node[i];
175
+ for (let i = 0; i < node.length; i++) {
176
+ const child = node[i];
177
if (isValidElement(child)) {
178
validateExplicitKey(child, parentType);
179
}
@@ -184,13 +184,13 @@ function validateChildKeys(node, parentType) {
184
node._store.validated = true;
185
}
186
} else if (node) {
187
- var iteratorFn = getIteratorFn(node);
187
+ const iteratorFn = getIteratorFn(node);
188
if (typeof iteratorFn === 'function') {
189
// Entry iterators used to provide implicit keys,
190
// but now we print a separate warning for them later.
191
if (iteratorFn !== node.entries) {
192
- var iterator = iteratorFn.call(node);
193
- var step;
192
+ const iterator = iteratorFn.call(node);
193
+ let step;
194
while (!(step = iterator.next()).done) {
195
if (isValidElement(step.value)) {
196
validateExplicitKey(step.value, parentType);
@@ -208,12 +208,12 @@ function validateChildKeys(node, parentType) {
208
* @param {ReactElement} element
209
*/
210
function validatePropTypes(element) {
211
- var componentClass = element.type;
211
+ const componentClass = element.type;
212
if (typeof componentClass !== 'function') {
213
return;
214
}
215
- var name = componentClass.displayName || componentClass.name;
216
- var propTypes = componentClass.propTypes;
215
+ const name = componentClass.displayName || componentClass.name;
216
+ const propTypes = componentClass.propTypes;
217
if (propTypes) {
218
currentlyValidatingElement = element;
219
checkPropTypes(propTypes, element.props, 'prop', name, getStackAddendum);
@@ -270,7 +270,7 @@ function validateFragmentProps(fragment) {
270
}
271
272
export function createElementWithValidation(type, props, children) {
273
- var validType =
273
+ const validType =
274
typeof type === 'string' ||
275
typeof type === 'function' ||
276
typeof type === 'symbol' ||
@@ -278,7 +278,7 @@ export function createElementWithValidation(type, props, children) {
278
// We warn in this case but don't throw. We expect the element creation to
279
// succeed and there will likely be errors in render.
280
if (!validType) {
281
- var info = '';
281
+ let info = '';
282
if (
283
type === undefined ||
284
(typeof type === 'object' &&
@@ -290,7 +290,7 @@ export function createElementWithValidation(type, props, children) {
290
"it's defined in, or you might have mixed up default and named imports.";
291
}
292
293
- var sourceInfo = getSourceInfoErrorAddendum(props);
293
+ const sourceInfo = getSourceInfoErrorAddendum(props);
294
if (sourceInfo) {
295
info += sourceInfo;
296
} else {
@@ -309,7 +309,7 @@ export function createElementWithValidation(type, props, children) {
309
);
310
}
311
312
- var element = createElement.apply(this, arguments);
312
+ const element = createElement.apply(this, arguments);
313
314
// The result can be nullish if a mock or a custom function is used.
315
// TODO: Drop this when these are no longer allowed as the type argument.
@@ -323,7 +323,7 @@ export function createElementWithValidation(type, props, children) {
323
// (Rendering will throw with a helpful message and as soon as the type is
324
// fixed, the key warnings will appear.)
325
if (validType) {
326
- for (var i = 2; i < arguments.length; i++) {
326
+ for (let i = 2; i < arguments.length; i++) {
327
validateChildKeys(arguments[i], type);
328
}
329
}
@@ -338,7 +338,7 @@ export function createElementWithValidation(type, props, children) {
338
}
339
340
export function createFactoryWithValidation(type) {
341
- var validatedFactory = createElementWithValidation.bind(null, type);
341
+ const validatedFactory = createElementWithValidation.bind(null, type);
342
// Legacy hook TODO: Warn if this is accessed
343
validatedFactory.type = type;
344
@@ -363,8 +363,8 @@ export function createFactoryWithValidation(type) {
363
}
364
365
export function cloneElementWithValidation(element, props, children) {
366
- var newElement = cloneElement.apply(this, arguments);
367
- for (var i = 2; i < arguments.length; i++) {
366
+ const newElement = cloneElement.apply(this, arguments);
367
+ for (let i = 2; i < arguments.length; i++) {
368
validateChildKeys(arguments[i], newElement.type);
369
}
370
validatePropTypes(newElement);
packages/react/src/ReactNoopUpdateQueue.js
+3
-3
@@ -7,11 +7,11 @@
7
8
import warning from 'fbjs/lib/warning';
9
10
-var didWarnStateUpdateForUnmountedComponent = {};
10
+const didWarnStateUpdateForUnmountedComponent = {};
11
12
function warnNoop(publicInstance, callerName) {
13
if (__DEV__) {
14
- var constructor = publicInstance.constructor;
14
+ const constructor = publicInstance.constructor;
15
const componentName =
16
(constructor && (constructor.displayName || constructor.name)) ||
17
'ReactClass';
@@ -35,7 +35,7 @@ function warnNoop(publicInstance, callerName) {
35
/**
36
* This is the abstract API for an update queue.
37
*/
38
-var ReactNoopUpdateQueue = {
38
+const ReactNoopUpdateQueue = {
39
/**
40
* Checks whether or not this composite component is mounted.
41
* @param {ReactClass} publicInstance The instance we want to test.
packages/react/src/__tests__/ReactAsyncClassComponent-test.internal.js
+3
-3
@@ -9,9 +9,9 @@
9
10
'use strict';
11
12
-var React;
13
-var ReactFeatureFlags;
14
-var ReactTestRenderer;
12
+let React;
13
+let ReactFeatureFlags;
14
+let ReactTestRenderer;
15
16
describe('ReactAsyncClassComponent', () => {
17
describe('debugRenderPhaseSideEffects', () => {
packages/react/src/__tests__/ReactChildren-test.js
+167
-157
@@ -10,8 +10,8 @@
10
'use strict';
11
12
describe('ReactChildren', () => {
13
- var React;
14
- var ReactTestUtils;
13
+ let React;
14
+ let ReactTestUtils;
15
16
function normalizeCodeLocInfo(str) {
17
return str && str.replace(/at .+?:\d+/g, 'at **');
@@ -24,22 +24,22 @@ describe('ReactChildren', () => {
24
});
25
26
it('should support identity for simple', () => {
27
- var context = {};
28
- var callback = jasmine.createSpy().and.callFake(function(kid, index) {
27
+ const context = {};
28
+ const callback = jasmine.createSpy().and.callFake(function(kid, index) {
29
expect(this).toBe(context);
30
return kid;
31
});
32
33
- var simpleKid = <span key="simple" />;
33
+ const simpleKid = <span key="simple" />;
34
35
// First pass children into a component to fully simulate what happens when
36
// using structures that arrive from transforms.
37
38
- var instance = <div>{simpleKid}</div>;
38
+ const instance = <div>{simpleKid}</div>;
39
React.Children.forEach(instance.props.children, callback, context);
40
expect(callback).toHaveBeenCalledWith(simpleKid, 0);
41
callback.calls.reset();
42
- var mappedChildren = React.Children.map(
42
+ const mappedChildren = React.Children.map(
43
instance.props.children,
44
callback,
45
context,
@@ -123,18 +123,18 @@ describe('ReactChildren', () => {
123
});
124
125
it('should treat single arrayless child as being in array', () => {
126
- var context = {};
127
- var callback = jasmine.createSpy().and.callFake(function(kid, index) {
126
+ const context = {};
127
+ const callback = jasmine.createSpy().and.callFake(function(kid, index) {
128
expect(this).toBe(context);
129
return kid;
130
});
131
132
- var simpleKid = <span />;
133
- var instance = <div>{simpleKid}</div>;
132
+ const simpleKid = <span />;
133
+ const instance = <div>{simpleKid}</div>;
134
React.Children.forEach(instance.props.children, callback, context);
135
expect(callback).toHaveBeenCalledWith(simpleKid, 0);
136
callback.calls.reset();
137
- var mappedChildren = React.Children.map(
137
+ const mappedChildren = React.Children.map(
138
instance.props.children,
139
callback,
140
context,
@@ -144,18 +144,18 @@ describe('ReactChildren', () => {
144
});
145
146
it('should treat single child in array as expected', () => {
147
- var context = {};
148
- var callback = jasmine.createSpy().and.callFake(function(kid, index) {
147
+ const context = {};
148
+ const callback = jasmine.createSpy().and.callFake(function(kid, index) {
149
expect(this).toBe(context);
150
return kid;
151
});
152
153
- var simpleKid = <span key="simple" />;
154
- var instance = <div>{[simpleKid]}</div>;
153
+ const simpleKid = <span key="simple" />;
154
+ const instance = <div>{[simpleKid]}</div>;
155
React.Children.forEach(instance.props.children, callback, context);
156
expect(callback).toHaveBeenCalledWith(simpleKid, 0);
157
callback.calls.reset();
158
- var mappedChildren = React.Children.map(
158
+ const mappedChildren = React.Children.map(
159
instance.props.children,
160
callback,
161
context,
@@ -165,19 +165,19 @@ describe('ReactChildren', () => {
165
});
166
167
it('should be called for each child', () => {
168
- var zero = <div key="keyZero" />;
169
- var one = null;
170
- var two = <div key="keyTwo" />;
171
- var three = null;
172
- var four = <div key="keyFour" />;
173
- var context = {};
174
-
175
- var callback = jasmine.createSpy().and.callFake(function(kid) {
168
+ const zero = <div key="keyZero" />;
169
+ const one = null;
170
+ const two = <div key="keyTwo" />;
171
+ const three = null;
172
+ const four = <div key="keyFour" />;
173
+ const context = {};
174
+
175
+ const callback = jasmine.createSpy().and.callFake(function(kid) {
176
expect(this).toBe(context);
177
return kid;
178
});
179
180
- var instance = (
180
+ const instance = (
181
<div>
182
{zero}
183
{one}
@@ -199,7 +199,7 @@ describe('ReactChildren', () => {
199
React.Children.forEach(instance.props.children, callback, context);
200
assertCalls();
201
202
- var mappedChildren = React.Children.map(
202
+ const mappedChildren = React.Children.map(
203
instance.props.children,
204
callback,
205
context,
@@ -213,17 +213,17 @@ describe('ReactChildren', () => {
213
});
214
215
it('should traverse children of different kinds', () => {
216
- var div = <div key="divNode" />;
217
- var span = <span key="spanNode" />;
218
- var a = <a key="aNode" />;
216
+ const div = <div key="divNode" />;
217
+ const span = <span key="spanNode" />;
218
+ const a = <a key="aNode" />;
219
220
- var context = {};
221
- var callback = jasmine.createSpy().and.callFake(function(kid) {
220
+ const context = {};
221
+ const callback = jasmine.createSpy().and.callFake(function(kid) {
222
expect(this).toBe(context);
223
return kid;
224
});
225
226
- var instance = (
226
+ const instance = (
227
<div>
228
{div}
229
{[[span]]}
@@ -254,7 +254,7 @@ describe('ReactChildren', () => {
254
React.Children.forEach(instance.props.children, callback, context);
255
assertCalls();
256
257
- var mappedChildren = React.Children.map(
257
+ const mappedChildren = React.Children.map(
258
instance.props.children,
259
callback,
260
context,
@@ -270,19 +270,19 @@ describe('ReactChildren', () => {
270
});
271
272
it('should be called for each child in nested structure', () => {
273
- var zero = <div key="keyZero" />;
274
- var one = null;
275
- var two = <div key="keyTwo" />;
276
- var three = null;
277
- var four = <div key="keyFour" />;
278
- var five = <div key="keyFive" />;
279
-
280
- var context = {};
281
- var callback = jasmine.createSpy().and.callFake(function(kid) {
273
+ const zero = <div key="keyZero" />;
274
+ const one = null;
275
+ const two = <div key="keyTwo" />;
276
+ const three = null;
277
+ const four = <div key="keyFour" />;
278
+ const five = <div key="keyFive" />;
279
+
280
+ const context = {};
281
+ const callback = jasmine.createSpy().and.callFake(function(kid) {
282
return kid;
283
});
284
285
- var instance = <div>{[[zero, one, two], [three, four], five]}</div>;
285
+ const instance = <div>{[[zero, one, two], [three, four], five]}</div>;
286
287
function assertCalls() {
288
expect(callback.calls.count()).toBe(6);
@@ -298,7 +298,7 @@ describe('ReactChildren', () => {
298
React.Children.forEach(instance.props.children, callback, context);
299
assertCalls();
300
301
- var mappedChildren = React.Children.map(
301
+ const mappedChildren = React.Children.map(
302
instance.props.children,
303
callback,
304
context,
@@ -313,15 +313,15 @@ describe('ReactChildren', () => {
313
});
314
315
it('should retain key across two mappings', () => {
316
- var zeroForceKey = <div key="keyZero" />;
317
- var oneForceKey = <div key="keyOne" />;
318
- var context = {};
319
- var callback = jasmine.createSpy().and.callFake(function(kid) {
316
+ const zeroForceKey = <div key="keyZero" />;
317
+ const oneForceKey = <div key="keyOne" />;
318
+ const context = {};
319
+ const callback = jasmine.createSpy().and.callFake(function(kid) {
320
expect(this).toBe(context);
321
return kid;
322
});
323
324
- var forcedKeys = (
324
+ const forcedKeys = (
325
<div>
326
{zeroForceKey}
327
{oneForceKey}
@@ -337,7 +337,7 @@ describe('ReactChildren', () => {
337
React.Children.forEach(forcedKeys.props.children, callback, context);
338
assertCalls();
339
340
- var mappedChildren = React.Children.map(
340
+ const mappedChildren = React.Children.map(
341
forcedKeys.props.children,
342
callback,
343
context,
@@ -351,9 +351,9 @@ describe('ReactChildren', () => {
351
352
it('should be called for each child in an iterable without keys', () => {
353
spyOnDev(console, 'error');
354
- var threeDivIterable = {
354
+ const threeDivIterable = {
355
'@@iterator': function() {
356
- var i = 0;
356
+ let i = 0;
357
return {
358
next: function() {
359
if (i++ < 3) {
@@ -366,13 +366,13 @@ describe('ReactChildren', () => {
366
},
367
};
368
369
- var context = {};
370
- var callback = jasmine.createSpy().and.callFake(function(kid) {
369
+ const context = {};
370
+ const callback = jasmine.createSpy().and.callFake(function(kid) {
371
expect(this).toBe(context);
372
return kid;
373
});
374
375
- var instance = <div>{threeDivIterable}</div>;
375
+ const instance = <div>{threeDivIterable}</div>;
376
377
function assertCalls() {
378
expect(callback.calls.count()).toBe(3);
@@ -392,7 +392,7 @@ describe('ReactChildren', () => {
392
console.error.calls.reset();
393
}
394
395
- var mappedChildren = React.Children.map(
395
+ const mappedChildren = React.Children.map(
396
instance.props.children,
397
callback,
398
context,
@@ -409,9 +409,9 @@ describe('ReactChildren', () => {
409
});
410
411
it('should be called for each child in an iterable with keys', () => {
412
- var threeDivIterable = {
412
+ const threeDivIterable = {
413
'@@iterator': function() {
414
- var i = 0;
414
+ let i = 0;
415
return {
416
next: function() {
417
if (i++ < 3) {
@@ -424,13 +424,13 @@ describe('ReactChildren', () => {
424
},
425
};
426
427
- var context = {};
428
- var callback = jasmine.createSpy().and.callFake(function(kid) {
427
+ const context = {};
428
+ const callback = jasmine.createSpy().and.callFake(function(kid) {
429
expect(this).toBe(context);
430
return kid;
431
});
432
433
- var instance = <div>{threeDivIterable}</div>;
433
+ const instance = <div>{threeDivIterable}</div>;
434
435
function assertCalls() {
436
expect(callback.calls.count()).toBe(3);
@@ -443,7 +443,7 @@ describe('ReactChildren', () => {
443
React.Children.forEach(instance.props.children, callback, context);
444
assertCalls();
445
446
- var mappedChildren = React.Children.map(
446
+ const mappedChildren = React.Children.map(
447
instance.props.children,
448
callback,
449
context,
@@ -464,7 +464,7 @@ describe('ReactChildren', () => {
464
/*eslint-enable no-extend-native */
465
466
try {
467
- var instance = (
467
+ const instance = (
468
<div>
469
{5}
470
{12}
@@ -472,13 +472,13 @@ describe('ReactChildren', () => {
472
</div>
473
);
474
475
- var context = {};
476
- var callback = jasmine.createSpy().and.callFake(function(kid) {
475
+ const context = {};
476
+ const callback = jasmine.createSpy().and.callFake(function(kid) {
477
expect(this).toBe(context);
478
return kid;
479
});
480
481
- var assertCalls = function() {
481
+ const assertCalls = function() {
482
expect(callback.calls.count()).toBe(3);
483
expect(callback).toHaveBeenCalledWith(5, 0);
484
expect(callback).toHaveBeenCalledWith(12, 1);
@@ -489,7 +489,7 @@ describe('ReactChildren', () => {
489
React.Children.forEach(instance.props.children, callback, context);
490
assertCalls();
491
492
- var mappedChildren = React.Children.map(
492
+ const mappedChildren = React.Children.map(
493
instance.props.children,
494
callback,
495
context,
@@ -507,15 +507,15 @@ describe('ReactChildren', () => {
507
Number.prototype.key = 'rocks';
508
/*eslint-enable no-extend-native */
509
510
- var instance = (
510
+ const instance = (
511
<div>
512
{'a'}
513
{13}
514
</div>
515
);
516
517
- var context = {};
518
- var callback = jasmine.createSpy().and.callFake(function(kid) {
517
+ const context = {};
518
+ const callback = jasmine.createSpy().and.callFake(function(kid) {
519
expect(this).toBe(context);
520
return kid;
521
});
@@ -530,7 +530,7 @@ describe('ReactChildren', () => {
530
React.Children.forEach(instance.props.children, callback, context);
531
assertCalls();
532
533
- var mappedChildren = React.Children.map(
533
+ const mappedChildren = React.Children.map(
534
instance.props.children,
535
callback,
536
context,
@@ -543,14 +543,14 @@ describe('ReactChildren', () => {
543
});
544
545
it('should pass key to returned component', () => {
546
- var mapFn = function(kid, index) {
546
+ const mapFn = function(kid, index) {
547
return <div>{kid}</div>;
548
};
549
550
- var simpleKid = <span key="simple" />;
550
+ const simpleKid = <span key="simple" />;
551
552
- var instance = <div>{simpleKid}</div>;
553
- var mappedChildren = React.Children.map(instance.props.children, mapFn);
552
+ const instance = <div>{simpleKid}</div>;
553
+ const mappedChildren = React.Children.map(instance.props.children, mapFn);
554
555
expect(React.Children.count(mappedChildren)).toBe(1);
556
expect(mappedChildren[0]).not.toBe(simpleKid);
@@ -559,21 +559,21 @@ describe('ReactChildren', () => {
559
});
560
561
it('should invoke callback with the right context', () => {
562
- var lastContext;
563
- var callback = function(kid, index) {
562
+ let lastContext;
563
+ const callback = function(kid, index) {
564
lastContext = this;
565
return this;
566
};
567
568
// TODO: Use an object to test, after non-object fragments has fully landed.
569
- var scopeTester = 'scope tester';
569
+ const scopeTester = 'scope tester';
570
571
- var simpleKid = <span key="simple" />;
572
- var instance = <div>{simpleKid}</div>;
571
+ const simpleKid = <span key="simple" />;
572
+ const instance = <div>{simpleKid}</div>;
573
React.Children.forEach(instance.props.children, callback, scopeTester);
574
expect(lastContext).toBe(scopeTester);
575
576
- var mappedChildren = React.Children.map(
576
+ const mappedChildren = React.Children.map(
577
instance.props.children,
578
callback,
579
scopeTester,
@@ -584,24 +584,24 @@ describe('ReactChildren', () => {
584
});
585
586
it('should be called for each child', () => {
587
- var zero = <div key="keyZero" />;
588
- var one = null;
589
- var two = <div key="keyTwo" />;
590
- var three = null;
591
- var four = <div key="keyFour" />;
587
+ const zero = <div key="keyZero" />;
588
+ const one = null;
589
+ const two = <div key="keyTwo" />;
590
+ const three = null;
591
+ const four = <div key="keyFour" />;
592
593
- var mapped = [
593
+ const mapped = [
594
<div key="giraffe" />, // Key should be joined to obj key
595
null, // Key should be added even if we don't supply it!
596
<div />, // Key should be added even if not supplied!
597
<span />, // Map from null to something.
598
<div key="keyFour" />,
599
];
600
- var callback = jasmine.createSpy().and.callFake(function(kid, index) {
600
+ const callback = jasmine.createSpy().and.callFake(function(kid, index) {
601
return mapped[index];
602
});
603
604
- var instance = (
604
+ const instance = (
605
<div>
606
{zero}
607
{one}
@@ -619,7 +619,10 @@ describe('ReactChildren', () => {
619
expect(callback).toHaveBeenCalledWith(four, 4);
620
callback.calls.reset();
621
622
- var mappedChildren = React.Children.map(instance.props.children, callback);
622
+ const mappedChildren = React.Children.map(
623
+ instance.props.children,
624
+ callback,
625
+ );
626
expect(callback.calls.count()).toBe(5);
627
expect(React.Children.count(mappedChildren)).toBe(4);
628
// Keys default to indices.
@@ -643,19 +646,19 @@ describe('ReactChildren', () => {
646
});
647
648
it('should be called for each child in nested structure', () => {
646
- var zero = <div key="keyZero" />;
647
- var one = null;
648
- var two = <div key="keyTwo" />;
649
- var three = null;
650
- var four = <div key="keyFour" />;
651
- var five = <div key="keyFive" />;
652
-
653
- var zeroMapped = <div key="giraffe" />; // Key should be overridden
654
- var twoMapped = <div />; // Key should be added even if not supplied!
655
- var fourMapped = <div key="keyFour" />;
656
- var fiveMapped = <div />;
657
-
658
- var callback = jasmine.createSpy().and.callFake(function(kid) {
649
+ const zero = <div key="keyZero" />;
650
+ const one = null;
651
+ const two = <div key="keyTwo" />;
652
+ const three = null;
653
+ const four = <div key="keyFour" />;
654
+ const five = <div key="keyFive" />;
655
+
656
+ const zeroMapped = <div key="giraffe" />; // Key should be overridden
657
+ const twoMapped = <div />; // Key should be added even if not supplied!
658
+ const fourMapped = <div key="keyFour" />;
659
+ const fiveMapped = <div />;
660
+
661
+ const callback = jasmine.createSpy().and.callFake(function(kid) {
662
switch (kid) {
663
case zero:
664
return zeroMapped;
@@ -670,8 +673,8 @@ describe('ReactChildren', () => {
673
}
674
});
675
673
- var frag = [[zero, one, two], [three, four], five];
674
- var instance = <div>{[frag]}</div>;
676
+ const frag = [[zero, one, two], [three, four], five];
677
+ const instance = <div>{[frag]}</div>;
678
679
React.Children.forEach(instance.props.children, callback);
680
expect(callback.calls.count()).toBe(6);
@@ -683,7 +686,10 @@ describe('ReactChildren', () => {
686
expect(callback).toHaveBeenCalledWith(five, 5);
687
callback.calls.reset();
688
686
- var mappedChildren = React.Children.map(instance.props.children, callback);
689
+ const mappedChildren = React.Children.map(
690
+ instance.props.children,
691
+ callback,
692
+ );
693
expect(callback.calls.count()).toBe(6);
694
expect(callback).toHaveBeenCalledWith(zero, 0);
695
expect(callback).toHaveBeenCalledWith(one, 1);
@@ -713,38 +719,38 @@ describe('ReactChildren', () => {
719
});
720
721
it('should retain key across two mappings', () => {
716
- var zeroForceKey = <div key="keyZero" />;
717
- var oneForceKey = <div key="keyOne" />;
722
+ const zeroForceKey = <div key="keyZero" />;
723
+ const oneForceKey = <div key="keyOne" />;
724
725
// Key should be joined to object key
720
- var zeroForceKeyMapped = <div key="giraffe" />;
726
+ const zeroForceKeyMapped = <div key="giraffe" />;
727
// Key should be added even if we don't supply it!
722
- var oneForceKeyMapped = <div />;
728
+ const oneForceKeyMapped = <div />;
729
724
- var mapFn = function(kid, index) {
730
+ const mapFn = function(kid, index) {
731
return index === 0 ? zeroForceKeyMapped : oneForceKeyMapped;
732
};
733
728
- var forcedKeys = (
734
+ const forcedKeys = (
735
<div>
736
{zeroForceKey}
737
{oneForceKey}
738
</div>
739
);
740
735
- var expectedForcedKeys = ['giraffe/.$keyZero', '.$keyOne'];
736
- var mappedChildrenForcedKeys = React.Children.map(
741
+ const expectedForcedKeys = ['giraffe/.$keyZero', '.$keyOne'];
742
+ const mappedChildrenForcedKeys = React.Children.map(
743
forcedKeys.props.children,
744
mapFn,
745
);
740
- var mappedForcedKeys = mappedChildrenForcedKeys.map(c => c.key);
746
+ const mappedForcedKeys = mappedChildrenForcedKeys.map(c => c.key);
747
expect(mappedForcedKeys).toEqual(expectedForcedKeys);
748
743
- var expectedRemappedForcedKeys = [
749
+ const expectedRemappedForcedKeys = [
750
'giraffe/.$giraffe/.$keyZero',
751
'.$.$keyOne',
752
];
747
- var remappedChildrenForcedKeys = React.Children.map(
753
+ const remappedChildrenForcedKeys = React.Children.map(
754
mappedChildrenForcedKeys,
755
mapFn,
756
);
@@ -754,14 +760,14 @@ describe('ReactChildren', () => {
760
});
761
762
it('should not throw if key provided is a dupe with array key', () => {
757
- var zero = <div />;
758
- var one = <div key="0" />;
763
+ const zero = <div />;
764
+ const one = <div key="0" />;
765
760
- var mapFn = function() {
766
+ const mapFn = function() {
767
return null;
768
};
769
764
- var instance = (
770
+ const instance = (
771
<div>
772
{zero}
773
{one}
@@ -774,68 +780,70 @@ describe('ReactChildren', () => {
780
});
781
782
it('should use the same key for a cloned element', () => {
777
- var instance = (
783
+ const instance = (
784
<div>
785
<div />
786
</div>
787
);
788
783
- var mapped = React.Children.map(
789
+ const mapped = React.Children.map(
790
instance.props.children,
791
element => element,
792
);
793
788
- var mappedWithClone = React.Children.map(instance.props.children, element =>
789
- React.cloneElement(element),
794
+ const mappedWithClone = React.Children.map(
795
+ instance.props.children,
796
+ element => React.cloneElement(element),
797
);
798
799
expect(mapped[0].key).toBe(mappedWithClone[0].key);
800
});
801
802
it('should use the same key for a cloned element with key', () => {
796
- var instance = (
803
+ const instance = (
804
<div>
805
<div key="unique" />
806
</div>
807
);
808
802
- var mapped = React.Children.map(
809
+ const mapped = React.Children.map(
810
instance.props.children,
811
element => element,
812
);
813
807
- var mappedWithClone = React.Children.map(instance.props.children, element =>
808
- React.cloneElement(element, {key: 'unique'}),
814
+ const mappedWithClone = React.Children.map(
815
+ instance.props.children,
816
+ element => React.cloneElement(element, {key: 'unique'}),
817
);
818
819
expect(mapped[0].key).toBe(mappedWithClone[0].key);
820
});
821
822
it('should return 0 for null children', () => {
815
- var numberOfChildren = React.Children.count(null);
823
+ const numberOfChildren = React.Children.count(null);
824
expect(numberOfChildren).toBe(0);
825
});
826
827
it('should return 0 for undefined children', () => {
820
- var numberOfChildren = React.Children.count(undefined);
828
+ const numberOfChildren = React.Children.count(undefined);
829
expect(numberOfChildren).toBe(0);
830
});
831
832
it('should return 1 for single child', () => {
825
- var simpleKid = <span key="simple" />;
826
- var instance = <div>{simpleKid}</div>;
827
- var numberOfChildren = React.Children.count(instance.props.children);
833
+ const simpleKid = <span key="simple" />;
834
+ const instance = <div>{simpleKid}</div>;
835
+ const numberOfChildren = React.Children.count(instance.props.children);
836
expect(numberOfChildren).toBe(1);
837
});
838
839
it('should count the number of children in flat structure', () => {
832
- var zero = <div key="keyZero" />;
833
- var one = null;
834
- var two = <div key="keyTwo" />;
835
- var three = null;
836
- var four = <div key="keyFour" />;
840
+ const zero = <div key="keyZero" />;
841
+ const one = null;
842
+ const two = <div key="keyTwo" />;
843
+ const three = null;
844
+ const four = <div key="keyFour" />;
845
838
- var instance = (
846
+ const instance = (
847
<div>
848
{zero}
849
{one}
@@ -844,20 +852,22 @@ describe('ReactChildren', () => {
852
{four}
853
</div>
854
);
847
- var numberOfChildren = React.Children.count(instance.props.children);
855
+ const numberOfChildren = React.Children.count(instance.props.children);
856
expect(numberOfChildren).toBe(5);
857
});
858
859
it('should count the number of children in nested structure', () => {
852
- var zero = <div key="keyZero" />;
853
- var one = null;
854
- var two = <div key="keyTwo" />;
855
- var three = null;
856
- var four = <div key="keyFour" />;
857
- var five = <div key="keyFive" />;
858
-
859
- var instance = <div>{[[[zero, one, two], [three, four], five], null]}</div>;
860
- var numberOfChildren = React.Children.count(instance.props.children);
860
+ const zero = <div key="keyZero" />;
861
+ const one = null;
862
+ const two = <div key="keyTwo" />;
863
+ const three = null;
864
+ const four = <div key="keyFour" />;
865
+ const five = <div key="keyFive" />;
866
+
867
+ const instance = (
868
+ <div>{[[[zero, one, two], [three, four], five], null]}</div>
869
+ );
870
+ const numberOfChildren = React.Children.count(instance.props.children);
871
expect(numberOfChildren).toBe(7);
872
});
873
@@ -871,7 +881,7 @@ describe('ReactChildren', () => {
881
React.Children.toArray([<div />])[0].key,
882
);
883
874
- var flattened = React.Children.toArray([
884
+ const flattened = React.Children.toArray([
885
[<div key="apple" />, <div key="banana" />, <div key="camel" />],
886
[<div key="banana" />, <div key="camel" />, <div key="deli" />],
887
]);
@@ -880,7 +890,7 @@ describe('ReactChildren', () => {
890
expect(flattened[3].key).toContain('banana');
891
expect(flattened[1].key).not.toBe(flattened[3].key);
892
883
- var reversed = React.Children.toArray([
893
+ const reversed = React.Children.toArray([
894
[<div key="camel" />, <div key="banana" />, <div key="apple" />],
895
[<div key="deli" />, <div key="camel" />, <div key="banana" />],
896
]);
@@ -899,15 +909,15 @@ describe('ReactChildren', () => {
909
});
910
911
it('should escape keys', () => {
902
- var zero = <div key="1" />;
903
- var one = <div key="1=::=2" />;
904
- var instance = (
912
+ const zero = <div key="1" />;
913
+ const one = <div key="1=::=2" />;
914
+ const instance = (
915
<div>
916
{zero}
917
{one}
918
</div>
919
);
910
- var mappedChildren = React.Children.map(
920
+ const mappedChildren = React.Children.map(
921
instance.props.children,
922
kid => kid,
923
);
packages/react/src/__tests__/ReactClassEquivalence-test.js
+11
-11
@@ -9,26 +9,26 @@
9
10
'use strict';
11
12
-var spawnSync = require('child_process').spawnSync;
12
+const spawnSync = require('child_process').spawnSync;
13
14
describe('ReactClassEquivalence', () => {
15
it('tests the same thing for es6 classes and CoffeeScript', () => {
16
- var result1 = runJest('ReactCoffeeScriptClass-test.coffee');
17
- var result2 = runJest('ReactES6Class-test.js');
16
+ const result1 = runJest('ReactCoffeeScriptClass-test.coffee');
17
+ const result2 = runJest('ReactES6Class-test.js');
18
compareResults(result1, result2);
19
});
20
21
it('tests the same thing for es6 classes and TypeScript', () => {
22
- var result1 = runJest('ReactTypeScriptClass-test.ts');
23
- var result2 = runJest('ReactES6Class-test.js');
22
+ const result1 = runJest('ReactTypeScriptClass-test.ts');
23
+ const result2 = runJest('ReactES6Class-test.js');
24
compareResults(result1, result2);
25
});
26
});
27
28
function runJest(testFile) {
29
- var cwd = process.cwd();
30
- var extension = process.platform === 'win32' ? '.cmd' : '';
31
- var result = spawnSync('yarn' + extension, ['test', testFile], {
29
+ const cwd = process.cwd();
30
+ const extension = process.platform === 'win32' ? '.cmd' : '';
31
+ const result = spawnSync('yarn' + extension, ['test', testFile], {
32
cwd,
33
env: Object.assign({}, process.env, {
34
REACT_CLASS_EQUIVALENCE_TEST: 'true',
@@ -55,9 +55,9 @@ function runJest(testFile) {
55
}
56
57
function compareResults(a, b) {
58
- var regexp = /EQUIVALENCE.*$/gm;
59
- var aSpecs = (a.match(regexp) || []).sort().join('\n');
60
- var bSpecs = (b.match(regexp) || []).sort().join('\n');
58
+ const regexp = /EQUIVALENCE.*$/gm;
59
+ const aSpecs = (a.match(regexp) || []).sort().join('\n');
60
+ const bSpecs = (b.match(regexp) || []).sort().join('\n');
61
62
if (aSpecs.length === 0 && bSpecs.length === 0) {
63
throw new Error('No spec results found in the output');
packages/react/src/__tests__/ReactContextValidator-test.js
+12
-12
@@ -15,10 +15,10 @@
15
16
'use strict';
17
18
-var PropTypes;
19
-var React;
20
-var ReactDOM;
21
-var ReactTestUtils;
18
+let PropTypes;
19
+let React;
20
+let ReactDOM;
21
+let ReactTestUtils;
22
23
describe('ReactContextValidator', () => {
24
function normalizeCodeLocInfo(str) {
@@ -64,16 +64,16 @@ describe('ReactContextValidator', () => {
64
bar: PropTypes.number,
65
};
66
67
- var instance = ReactTestUtils.renderIntoDocument(
67
+ const instance = ReactTestUtils.renderIntoDocument(
68
<ComponentInFooBarContext />,
69
);
70
expect(instance.refs.child.context).toEqual({foo: 'abc'});
71
});
72
73
it('should pass next context to lifecycles', () => {
74
- var actualComponentWillReceiveProps;
75
- var actualShouldComponentUpdate;
76
- var actualComponentWillUpdate;
74
+ let actualComponentWillReceiveProps;
75
+ let actualShouldComponentUpdate;
76
+ let actualComponentWillUpdate;
77
78
class Parent extends React.Component {
79
getChildContext() {
@@ -115,7 +115,7 @@ describe('ReactContextValidator', () => {
115
foo: PropTypes.string,
116
};
117
118
- var container = document.createElement('div');
118
+ const container = document.createElement('div');
119
ReactDOM.render(<Parent foo="abc" />, container);
120
ReactDOM.render(<Parent foo="def" />, container);
121
expect(actualComponentWillReceiveProps).toEqual({foo: 'def'});
@@ -124,7 +124,7 @@ describe('ReactContextValidator', () => {
124
});
125
126
it('should not pass previous context to lifecycles', () => {
127
- var actualComponentDidUpdate;
127
+ let actualComponentDidUpdate;
128
129
class Parent extends React.Component {
130
getChildContext() {
@@ -154,7 +154,7 @@ describe('ReactContextValidator', () => {
154
foo: PropTypes.string,
155
};
156
157
- var container = document.createElement('div');
157
+ const container = document.createElement('div');
158
ReactDOM.render(<Parent foo="abc" />, container);
159
ReactDOM.render(<Parent foo="def" />, container);
160
expect(actualComponentDidUpdate).toHaveLength(2);
@@ -367,7 +367,7 @@ describe('ReactContextValidator', () => {
367
}
368
}
369
370
- var childContext;
370
+ let childContext;
371
class ChildContextConsumer extends React.Component {
372
render() {
373
childContext = this.context;
packages/react/src/__tests__/ReactES6Class-test.js
+19
-19
@@ -9,19 +9,19 @@
9
10
'use strict';
11
12
-var PropTypes;
13
-var React;
14
-var ReactDOM;
12
+let PropTypes;
13
+let React;
14
+let ReactDOM;
15
16
describe('ReactES6Class', () => {
17
- var container;
18
- var freeze = function(expectation) {
17
+ let container;
18
+ const freeze = function(expectation) {
19
Object.freeze(expectation);
20
return expectation;
21
};
22
- var Inner;
23
- var attachedListener = null;
24
- var renderedName = null;
22
+ let Inner;
23
+ let attachedListener = null;
24
+ let renderedName = null;
25
26
beforeEach(() => {
27
PropTypes = require('prop-types');
@@ -43,7 +43,7 @@ describe('ReactES6Class', () => {
43
});
44
45
function test(element, expectedTag, expectedClassName) {
46
- var instance = ReactDOM.render(element, container);
46
+ const instance = ReactDOM.render(element, container);
47
expect(container.firstChild).not.toBeNull();
48
expect(container.firstChild.tagName).toBe(expectedTag);
49
expect(container.firstChild.className).toBe(expectedClassName);
@@ -108,7 +108,7 @@ describe('ReactES6Class', () => {
108
return <span className={this.state.bar} />;
109
}
110
}
111
- var instance = test(<Foo initialValue="foo" />, 'DIV', 'foo');
111
+ const instance = test(<Foo initialValue="foo" />, 'DIV', 'foo');
112
instance.changeState();
113
test(<Foo />, 'SPAN', 'bar');
114
});
@@ -120,7 +120,7 @@ describe('ReactES6Class', () => {
120
this.state = {tag: context.tag, className: this.context.className};
121
}
122
render() {
123
- var Tag = this.state.tag;
123
+ const Tag = this.state.tag;
124
return <Tag className={this.state.className} />;
125
}
126
}
@@ -145,7 +145,7 @@ describe('ReactES6Class', () => {
145
});
146
147
it('renders only once when setting state in componentWillMount', () => {
148
- var renderCount = 0;
148
+ let renderCount = 0;
149
class Foo extends React.Component {
150
constructor(props) {
151
super(props);
@@ -261,7 +261,7 @@ describe('ReactES6Class', () => {
261
});
262
263
it('will call all the normal life cycle methods', () => {
264
- var lifeCycles = [];
264
+ let lifeCycles = [];
265
class Foo extends React.Component {
266
constructor() {
267
super();
@@ -311,8 +311,8 @@ describe('ReactES6Class', () => {
311
312
it('warns when classic properties are defined on the instance, but does not invoke them.', () => {
313
spyOnDev(console, 'error');
314
- var getDefaultPropsWasCalled = false;
315
- var getInitialStateWasCalled = false;
314
+ let getDefaultPropsWasCalled = false;
315
+ let getInitialStateWasCalled = false;
316
class Foo extends React.Component {
317
constructor() {
318
super();
@@ -417,7 +417,7 @@ describe('ReactES6Class', () => {
417
418
it('should throw AND warn when trying to access classic APIs', () => {
419
spyOnDev(console, 'warn');
420
- var instance = test(<Inner name="foo" />, 'DIV', 'foo');
420
+ const instance = test(<Inner name="foo" />, 'DIV', 'foo');
421
expect(() => instance.replaceState({})).toThrow();
422
expect(() => instance.isMounted()).toThrow();
423
if (__DEV__) {
@@ -456,13 +456,13 @@ describe('ReactES6Class', () => {
456
return <Inner name="foo" ref="inner" />;
457
}
458
}
459
- var instance = test(<Foo />, 'DIV', 'foo');
459
+ const instance = test(<Foo />, 'DIV', 'foo');
460
expect(instance.refs.inner.getName()).toBe('foo');
461
});
462
463
it('supports drilling through to the DOM using findDOMNode', () => {
464
- var instance = test(<Inner name="foo" />, 'DIV', 'foo');
465
- var node = ReactDOM.findDOMNode(instance);
464
+ const instance = test(<Inner name="foo" />, 'DIV', 'foo');
465
+ const node = ReactDOM.findDOMNode(instance);
466
expect(node).toBe(container.firstChild);
467
});
468
});
packages/react/src/__tests__/ReactElement-test.js
+50
-50
@@ -9,13 +9,13 @@
9
10
'use strict';
11
12
-var React;
13
-var ReactDOM;
14
-var ReactTestUtils;
12
+let React;
13
+let ReactDOM;
14
+let ReactTestUtils;
15
16
describe('ReactElement', () => {
17
- var ComponentClass;
18
- var originalSymbol;
17
+ let ComponentClass;
18
+ let originalSymbol;
19
20
beforeEach(() => {
21
jest.resetModules();
@@ -46,7 +46,7 @@ describe('ReactElement', () => {
46
});
47
48
it('returns a complete element according to spec', () => {
49
- var element = React.createFactory(ComponentClass)();
49
+ const element = React.createFactory(ComponentClass)();
50
expect(element.type).toBe(ComponentClass);
51
expect(element.key).toBe(null);
52
expect(element.ref).toBe(null);
@@ -59,7 +59,7 @@ describe('ReactElement', () => {
59
60
it('should warn when `key` is being accessed on composite element', () => {
61
spyOnDev(console, 'error');
62
- var container = document.createElement('div');
62
+ const container = document.createElement('div');
63
class Child extends React.Component {
64
render() {
65
return <div> {this.props.key} </div>;
@@ -93,7 +93,7 @@ describe('ReactElement', () => {
93
94
it('should warn when `key` is being accessed on a host element', () => {
95
spyOnDev(console, 'error');
96
- var element = <div key="3" />;
96
+ const element = <div key="3" />;
97
if (__DEV__) {
98
expect(console.error.calls.count()).toBe(0);
99
}
@@ -111,7 +111,7 @@ describe('ReactElement', () => {
111
112
it('should warn when `ref` is being accessed', () => {
113
spyOnDev(console, 'error');
114
- var container = document.createElement('div');
114
+ const container = document.createElement('div');
115
class Child extends React.Component {
116
render() {
117
return <div> {this.props.ref} </div>;
@@ -142,7 +142,7 @@ describe('ReactElement', () => {
142
});
143
144
it('allows a string to be passed as the type', () => {
145
- var element = React.createFactory('div')();
145
+ const element = React.createFactory('div')();
146
expect(element.type).toBe('div');
147
expect(element.key).toBe(null);
148
expect(element.ref).toBe(null);
@@ -154,7 +154,7 @@ describe('ReactElement', () => {
154
});
155
156
it('returns an immutable element', () => {
157
- var element = React.createFactory(ComponentClass)();
157
+ const element = React.createFactory(ComponentClass)();
158
if (__DEV__) {
159
expect(() => (element.type = 'div')).toThrow();
160
} else {
@@ -163,21 +163,21 @@ describe('ReactElement', () => {
163
});
164
165
it('does not reuse the original config object', () => {
166
- var config = {foo: 1};
167
- var element = React.createFactory(ComponentClass)(config);
166
+ const config = {foo: 1};
167
+ const element = React.createFactory(ComponentClass)(config);
168
expect(element.props.foo).toBe(1);
169
config.foo = 2;
170
expect(element.props.foo).toBe(1);
171
});
172
173
it('does not fail if config has no prototype', () => {
174
- var config = Object.create(null, {foo: {value: 1, enumerable: true}});
175
- var element = React.createFactory(ComponentClass)(config);
174
+ const config = Object.create(null, {foo: {value: 1, enumerable: true}});
175
+ const element = React.createFactory(ComponentClass)(config);
176
expect(element.props.foo).toBe(1);
177
});
178
179
it('extracts key and ref from the config', () => {
180
- var element = React.createFactory(ComponentClass)({
180
+ const element = React.createFactory(ComponentClass)({
181
key: '12',
182
ref: '34',
183
foo: '56',
@@ -193,7 +193,7 @@ describe('ReactElement', () => {
193
});
194
195
it('extracts null key and ref', () => {
196
- var element = React.createFactory(ComponentClass)({
196
+ const element = React.createFactory(ComponentClass)({
197
key: null,
198
ref: null,
199
foo: '12',
@@ -209,12 +209,12 @@ describe('ReactElement', () => {
209
});
210
211
it('ignores undefined key and ref', () => {
212
- var props = {
212
+ const props = {
213
foo: '56',
214
key: undefined,
215
ref: undefined,
216
};
217
- var element = React.createFactory(ComponentClass)(props);
217
+ const element = React.createFactory(ComponentClass)(props);
218
expect(element.type).toBe(ComponentClass);
219
expect(element.key).toBe(null);
220
expect(element.ref).toBe(null);
@@ -226,14 +226,14 @@ describe('ReactElement', () => {
226
});
227
228
it('ignores key and ref warning getters', () => {
229
- var elementA = React.createElement('div');
230
- var elementB = React.createElement('div', elementA.props);
229
+ const elementA = React.createElement('div');
230
+ const elementB = React.createElement('div', elementA.props);
231
expect(elementB.key).toBe(null);
232
expect(elementB.ref).toBe(null);
233
});
234
235
it('coerces the key to a string', () => {
236
- var element = React.createFactory(ComponentClass)({
236
+ const element = React.createFactory(ComponentClass)({
237
key: 12,
238
foo: '56',
239
});
@@ -248,8 +248,8 @@ describe('ReactElement', () => {
248
});
249
250
it('preserves the owner on the element', () => {
251
- var Component = React.createFactory(ComponentClass);
252
- var element;
251
+ const Component = React.createFactory(ComponentClass);
252
+ let element;
253
254
class Wrapper extends React.Component {
255
render() {
@@ -258,15 +258,15 @@ describe('ReactElement', () => {
258
}
259
}
260
261
- var instance = ReactTestUtils.renderIntoDocument(
261
+ const instance = ReactTestUtils.renderIntoDocument(
262
React.createElement(Wrapper),
263
);
264
expect(element._owner.stateNode).toBe(instance);
265
});
266
267
it('merges an additional argument onto the children prop', () => {
268
- var a = 1;
269
- var element = React.createFactory(ComponentClass)(
268
+ const a = 1;
269
+ const element = React.createFactory(ComponentClass)(
270
{
271
children: 'text',
272
},
@@ -276,14 +276,14 @@ describe('ReactElement', () => {
276
});
277
278
it('does not override children if no rest args are provided', () => {
279
- var element = React.createFactory(ComponentClass)({
279
+ const element = React.createFactory(ComponentClass)({
280
children: 'text',
281
});
282
expect(element.props.children).toBe('text');
283
});
284
285
it('overrides children if null is provided as an argument', () => {
286
- var element = React.createFactory(ComponentClass)(
286
+ const element = React.createFactory(ComponentClass)(
287
{
288
children: 'text',
289
},
@@ -293,10 +293,10 @@ describe('ReactElement', () => {
293
});
294
295
it('merges rest arguments onto the children prop in an array', () => {
296
- var a = 1;
297
- var b = 2;
298
- var c = 3;
299
- var element = React.createFactory(ComponentClass)(null, a, b, c);
296
+ const a = 1;
297
+ const b = 2;
298
+ const c = 3;
299
+ const element = React.createFactory(ComponentClass)(null, a, b, c);
300
expect(element.props.children).toEqual([1, 2, 3]);
301
});
302
@@ -310,7 +310,7 @@ describe('ReactElement', () => {
310
}
311
StaticMethodComponentClass.someStaticMethod = () => 'someReturnValue';
312
313
- var element = React.createElement(StaticMethodComponentClass);
313
+ const element = React.createElement(StaticMethodComponentClass);
314
expect(element.type.someStaticMethod()).toBe('someReturnValue');
315
});
316
@@ -334,15 +334,15 @@ describe('ReactElement', () => {
334
expect(React.isValidElement(Component)).toEqual(false);
335
expect(React.isValidElement({type: 'div', props: {}})).toEqual(false);
336
337
- var jsonElement = JSON.stringify(React.createElement('div'));
337
+ const jsonElement = JSON.stringify(React.createElement('div'));
338
expect(React.isValidElement(JSON.parse(jsonElement))).toBe(true);
339
});
340
341
// NOTE: We're explicitly not using JSX here. This is intended to test
342
// classic JS without JSX.
343
it('is indistinguishable from a plain object', () => {
344
- var element = React.createElement('div', {className: 'foo'});
345
- var object = {};
344
+ const element = React.createElement('div', {className: 'foo'});
345
+ const object = {};
346
expect(element.constructor).toBe(object.constructor);
347
});
348
@@ -356,8 +356,8 @@ describe('ReactElement', () => {
356
}
357
Component.defaultProps = {fruit: 'persimmon'};
358
359
- var container = document.createElement('div');
360
- var instance = ReactDOM.render(
359
+ const container = document.createElement('div');
360
+ const instance = ReactDOM.render(
361
React.createElement(Component, {fruit: 'mango'}),
362
container,
363
);
@@ -377,12 +377,12 @@ describe('ReactElement', () => {
377
}
378
Component.defaultProps = {prop: 'testKey'};
379
380
- var instance = ReactTestUtils.renderIntoDocument(
380
+ const instance = ReactTestUtils.renderIntoDocument(
381
React.createElement(Component),
382
);
383
expect(instance.props.prop).toBe('testKey');
384
385
- var inst2 = ReactTestUtils.renderIntoDocument(
385
+ const inst2 = ReactTestUtils.renderIntoDocument(
386
React.createElement(Component, {prop: null}),
387
);
388
expect(inst2.props.prop).toBe(null);
@@ -391,7 +391,7 @@ describe('ReactElement', () => {
391
it('throws when changing a prop (in dev) after element creation', () => {
392
class Outer extends React.Component {
393
render() {
394
- var el = <div className="moo" />;
394
+ const el = <div className="moo" />;
395
396
if (__DEV__) {
397
expect(function() {
@@ -406,7 +406,7 @@ describe('ReactElement', () => {
406
return el;
407
}
408
}
409
- var outer = ReactTestUtils.renderIntoDocument(<Outer color="orange" />);
409
+ const outer = ReactTestUtils.renderIntoDocument(<Outer color="orange" />);
410
if (__DEV__) {
411
expect(ReactDOM.findDOMNode(outer).className).toBe('moo');
412
} else {
@@ -415,10 +415,10 @@ describe('ReactElement', () => {
415
});
416
417
it('throws when adding a prop (in dev) after element creation', () => {
418
- var container = document.createElement('div');
418
+ const container = document.createElement('div');
419
class Outer extends React.Component {
420
render() {
421
- var el = <div>{this.props.sound}</div>;
421
+ const el = <div>{this.props.sound}</div>;
422
423
if (__DEV__) {
424
expect(function() {
@@ -434,7 +434,7 @@ describe('ReactElement', () => {
434
}
435
}
436
Outer.defaultProps = {sound: 'meow'};
437
- var outer = ReactDOM.render(<Outer />, container);
437
+ const outer = ReactDOM.render(<Outer />, container);
438
expect(ReactDOM.findDOMNode(outer).textContent).toBe('meow');
439
if (__DEV__) {
440
expect(ReactDOM.findDOMNode(outer).className).toBe('');
@@ -449,7 +449,7 @@ describe('ReactElement', () => {
449
return <div />;
450
}
451
}
452
- var test = ReactTestUtils.renderIntoDocument(<Test value={+undefined} />);
452
+ const test = ReactTestUtils.renderIntoDocument(<Test value={+undefined} />);
453
expect(test.props.value).toBeNaN();
454
});
455
@@ -459,8 +459,8 @@ describe('ReactElement', () => {
459
// Rudimentary polyfill
460
// Once all jest engines support Symbols natively we can swap this to test
461
// WITH native Symbols by default.
462
- var REACT_ELEMENT_TYPE = function() {}; // fake Symbol
463
- var OTHER_SYMBOL = function() {}; // another fake Symbol
462
+ const REACT_ELEMENT_TYPE = function() {}; // fake Symbol
463
+ const OTHER_SYMBOL = function() {}; // another fake Symbol
464
global.Symbol = function(name) {
465
return OTHER_SYMBOL;
466
};
@@ -492,7 +492,7 @@ describe('ReactElement', () => {
492
expect(React.isValidElement(Component)).toEqual(false);
493
expect(React.isValidElement({type: 'div', props: {}})).toEqual(false);
494
495
- var jsonElement = JSON.stringify(React.createElement('div'));
495
+ const jsonElement = JSON.stringify(React.createElement('div'));
496
expect(React.isValidElement(JSON.parse(jsonElement))).toBe(false);
497
});
498
});
packages/react/src/__tests__/ReactElementClone-test.js
+31
-31
@@ -9,13 +9,13 @@
9
10
'use strict';
11
12
-var PropTypes;
13
-var React;
14
-var ReactDOM;
15
-var ReactTestUtils;
12
+let PropTypes;
13
+let React;
14
+let ReactDOM;
15
+let ReactTestUtils;
16
17
describe('ReactElementClone', () => {
18
- var ComponentClass;
18
+ let ComponentClass;
19
20
beforeEach(() => {
21
PropTypes = require('prop-types');
@@ -47,7 +47,7 @@ describe('ReactElementClone', () => {
47
);
48
}
49
}
50
- var component = ReactTestUtils.renderIntoDocument(<Grandparent />);
50
+ const component = ReactTestUtils.renderIntoDocument(<Grandparent />);
51
expect(ReactDOM.findDOMNode(component).childNodes[0].className).toBe('xyz');
52
});
53
@@ -71,12 +71,12 @@ describe('ReactElementClone', () => {
71
);
72
}
73
}
74
- var component = ReactTestUtils.renderIntoDocument(<Grandparent />);
74
+ const component = ReactTestUtils.renderIntoDocument(<Grandparent />);
75
expect(ReactDOM.findDOMNode(component).childNodes[0].className).toBe('xyz');
76
});
77
78
it('does not fail if config has no prototype', () => {
79
- var config = Object.create(null, {foo: {value: 1, enumerable: true}});
79
+ const config = Object.create(null, {foo: {value: 1, enumerable: true}});
80
React.cloneElement(<div />, config);
81
});
82
@@ -95,7 +95,7 @@ describe('ReactElementClone', () => {
95
}
96
}
97
98
- var component = ReactTestUtils.renderIntoDocument(<Grandparent />);
98
+ const component = ReactTestUtils.renderIntoDocument(<Grandparent />);
99
expect(component.refs.yolo.tagName).toBe('DIV');
100
});
101
@@ -105,7 +105,7 @@ describe('ReactElementClone', () => {
105
return null;
106
}
107
}
108
- var clone = React.cloneElement(<Component />, {key: 'xyz'});
108
+ const clone = React.cloneElement(<Component />, {key: 'xyz'});
109
expect(clone.key).toBe('xyz');
110
});
111
@@ -142,7 +142,7 @@ describe('ReactElementClone', () => {
142
}
143
}
144
145
- var clone = React.cloneElement(
145
+ const clone = React.cloneElement(
146
<Component>xyz</Component>,
147
{children: <Component />},
148
<div />,
@@ -153,7 +153,7 @@ describe('ReactElementClone', () => {
153
});
154
155
it('should override children if undefined is provided as an argument', () => {
156
- var element = React.createElement(
156
+ const element = React.createElement(
157
ComponentClass,
158
{
159
children: 'text',
@@ -162,7 +162,7 @@ describe('ReactElementClone', () => {
162
);
163
expect(element.props.children).toBe(undefined);
164
165
- var element2 = React.cloneElement(
165
+ const element2 = React.cloneElement(
166
React.createElement(ComponentClass, {
167
children: 'text',
168
}),
@@ -175,7 +175,7 @@ describe('ReactElementClone', () => {
175
it('should support keys and refs', () => {
176
class Parent extends React.Component {
177
render() {
178
- var clone = React.cloneElement(this.props.children, {
178
+ const clone = React.cloneElement(this.props.children, {
179
key: 'xyz',
180
ref: 'xyz',
181
});
@@ -195,14 +195,14 @@ describe('ReactElementClone', () => {
195
}
196
}
197
198
- var component = ReactTestUtils.renderIntoDocument(<Grandparent />);
198
+ const component = ReactTestUtils.renderIntoDocument(<Grandparent />);
199
expect(component.refs.parent.refs.xyz.tagName).toBe('SPAN');
200
});
201
202
it('should steal the ref if a new ref is specified', () => {
203
class Parent extends React.Component {
204
render() {
205
- var clone = React.cloneElement(this.props.children, {ref: 'xyz'});
205
+ const clone = React.cloneElement(this.props.children, {ref: 'xyz'});
206
return <div>{clone}</div>;
207
}
208
}
@@ -217,7 +217,7 @@ describe('ReactElementClone', () => {
217
}
218
}
219
220
- var component = ReactTestUtils.renderIntoDocument(<Grandparent />);
220
+ const component = ReactTestUtils.renderIntoDocument(<Grandparent />);
221
expect(component.refs.child).toBeUndefined();
222
expect(component.refs.parent.refs.xyz.tagName).toBe('SPAN');
223
});
@@ -243,16 +243,16 @@ describe('ReactElementClone', () => {
243
}
244
Component.defaultProps = {prop: 'testKey'};
245
246
- var instance = React.createElement(Component);
247
- var clonedInstance = React.cloneElement(instance, {prop: undefined});
246
+ const instance = React.createElement(Component);
247
+ const clonedInstance = React.cloneElement(instance, {prop: undefined});
248
expect(clonedInstance.props.prop).toBe('testKey');
249
- var clonedInstance2 = React.cloneElement(instance, {prop: null});
249
+ const clonedInstance2 = React.cloneElement(instance, {prop: null});
250
expect(clonedInstance2.props.prop).toBe(null);
251
252
- var instance2 = React.createElement(Component, {prop: 'newTestKey'});
253
- var cloneInstance3 = React.cloneElement(instance2, {prop: undefined});
252
+ const instance2 = React.createElement(Component, {prop: 'newTestKey'});
253
+ const cloneInstance3 = React.cloneElement(instance2, {prop: undefined});
254
expect(cloneInstance3.props.prop).toBe('testKey');
255
- var cloneInstance4 = React.cloneElement(instance2, {});
255
+ const cloneInstance4 = React.cloneElement(instance2, {});
256
expect(cloneInstance4.props.prop).toBe('newTestKey');
257
});
258
@@ -318,24 +318,24 @@ describe('ReactElementClone', () => {
318
});
319
320
it('should ignore key and ref warning getters', () => {
321
- var elementA = React.createElement('div');
322
- var elementB = React.cloneElement(elementA, elementA.props);
321
+ const elementA = React.createElement('div');
322
+ const elementB = React.cloneElement(elementA, elementA.props);
323
expect(elementB.key).toBe(null);
324
expect(elementB.ref).toBe(null);
325
});
326
327
it('should ignore undefined key and ref', () => {
328
- var element = React.createFactory(ComponentClass)({
328
+ const element = React.createFactory(ComponentClass)({
329
key: '12',
330
ref: '34',
331
foo: '56',
332
});
333
- var props = {
333
+ const props = {
334
key: undefined,
335
ref: undefined,
336
foo: 'ef',
337
};
338
- var clone = React.cloneElement(element, props);
338
+ const clone = React.cloneElement(element, props);
339
expect(clone.type).toBe(ComponentClass);
340
expect(clone.key).toBe('12');
341
expect(clone.ref).toBe('34');
@@ -347,17 +347,17 @@ describe('ReactElementClone', () => {
347
});
348
349
it('should extract null key and ref', () => {
350
- var element = React.createFactory(ComponentClass)({
350
+ const element = React.createFactory(ComponentClass)({
351
key: '12',
352
ref: '34',
353
foo: '56',
354
});
355
- var props = {
355
+ const props = {
356
key: null,
357
ref: null,
358
foo: 'ef',
359
};
360
- var clone = React.cloneElement(element, props);
360
+ const clone = React.cloneElement(element, props);
361
expect(clone.type).toBe(ComponentClass);
362
expect(clone.key).toBe('null');
363
expect(clone.ref).toBe(null);
packages/react/src/__tests__/ReactElementValidator-test.js
+25
-25
@@ -12,17 +12,17 @@
12
// NOTE: We're explicitly not using JSX in this file. This is intended to test
13
// classic JS without JSX.
14
15
-var PropTypes;
16
-var React;
17
-var ReactDOM;
18
-var ReactTestUtils;
15
+let PropTypes;
16
+let React;
17
+let ReactDOM;
18
+let ReactTestUtils;
19
20
describe('ReactElementValidator', () => {
21
function normalizeCodeLocInfo(str) {
22
return str && str.replace(/at .+?:\d+/g, 'at **');
23
}
24
25
- var ComponentClass;
25
+ let ComponentClass;
26
27
beforeEach(() => {
28
jest.resetModules();
@@ -40,7 +40,7 @@ describe('ReactElementValidator', () => {
40
41
it('warns for keys for arrays of elements in rest args', () => {
42
spyOnDev(console, 'error');
43
- var Component = React.createFactory(ComponentClass);
43
+ const Component = React.createFactory(ComponentClass);
44
45
Component(null, [Component(), Component()]);
46
@@ -54,7 +54,7 @@ describe('ReactElementValidator', () => {
54
55
it('warns for keys for arrays of elements with owner info', () => {
56
spyOnDev(console, 'error');
57
- var Component = React.createFactory(ComponentClass);
57
+ const Component = React.createFactory(ComponentClass);
58
59
class InnerClass extends React.Component {
60
render() {
@@ -62,7 +62,7 @@ describe('ReactElementValidator', () => {
62
}
63
}
64
65
- var InnerComponent = React.createFactory(InnerClass);
65
+ const InnerComponent = React.createFactory(InnerClass);
66
67
class ComponentWrapper extends React.Component {
68
render() {
@@ -90,7 +90,7 @@ describe('ReactElementValidator', () => {
90
}
91
Object.defineProperty(Anonymous, 'name', {value: undefined});
92
93
- var divs = [<div />, <div />];
93
+ const divs = [<div />, <div />];
94
ReactTestUtils.renderIntoDocument(<Anonymous>{divs}</Anonymous>);
95
96
if (__DEV__) {
@@ -106,7 +106,7 @@ describe('ReactElementValidator', () => {
106
it('warns for keys for arrays of elements with no owner info', () => {
107
spyOnDev(console, 'error');
108
109
- var divs = [<div />, <div />];
109
+ const divs = [<div />, <div />];
110
ReactTestUtils.renderIntoDocument(<div>{divs}</div>);
111
112
if (__DEV__) {
@@ -171,14 +171,14 @@ describe('ReactElementValidator', () => {
171
172
it('warns for keys for iterables of elements in rest args', () => {
173
spyOnDev(console, 'error');
174
- var Component = React.createFactory(ComponentClass);
174
+ const Component = React.createFactory(ComponentClass);
175
176
- var iterable = {
176
+ const iterable = {
177
'@@iterator': function() {
178
- var i = 0;
178
+ let i = 0;
179
return {
180
next: function() {
181
- var done = ++i > 2;
181
+ const done = ++i > 2;
182
return {value: done ? undefined : Component(), done: done};
183
},
184
};
@@ -196,20 +196,20 @@ describe('ReactElementValidator', () => {
196
});
197
198
it('does not warns for arrays of elements with keys', () => {
199
- var Component = React.createFactory(ComponentClass);
199
+ const Component = React.createFactory(ComponentClass);
200
201
Component(null, [Component({key: '#1'}), Component({key: '#2'})]);
202
});
203
204
it('does not warns for iterable elements with keys', () => {
205
- var Component = React.createFactory(ComponentClass);
205
+ const Component = React.createFactory(ComponentClass);
206
207
- var iterable = {
207
+ const iterable = {
208
'@@iterator': function() {
209
- var i = 0;
209
+ let i = 0;
210
return {
211
next: function() {
212
- var done = ++i > 2;
212
+ const done = ++i > 2;
213
return {
214
value: done ? undefined : Component({key: '#' + i}),
215
done: done,
@@ -223,13 +223,13 @@ describe('ReactElementValidator', () => {
223
});
224
225
it('does not warn when the element is directly in rest args', () => {
226
- var Component = React.createFactory(ComponentClass);
226
+ const Component = React.createFactory(ComponentClass);
227
228
Component(null, Component(), Component());
229
});
230
231
it('does not warn when the array contains a non-element', () => {
232
- var Component = React.createFactory(ComponentClass);
232
+ const Component = React.createFactory(ComponentClass);
233
234
Component(null, [{}, {}]);
235
});
@@ -476,7 +476,7 @@ describe('ReactElementValidator', () => {
476
function TestComponent() {
477
return <div />;
478
}
479
- var TestFactory = React.createFactory(TestComponent);
479
+ const TestFactory = React.createFactory(TestComponent);
480
expect(TestFactory.type).toBe(TestComponent);
481
if (__DEV__) {
482
expect(console.warn.calls.count()).toBe(1);
@@ -502,7 +502,7 @@ describe('ReactElementValidator', () => {
502
}
503
}
504
505
- var node = document.createElement('div');
505
+ const node = document.createElement('div');
506
// This shouldn't cause a stack overflow or any other problems (#3883)
507
ReactTestUtils.renderIntoDocument(<DOMContainer>{node}</DOMContainer>);
508
});
@@ -531,7 +531,7 @@ describe('ReactElementValidator', () => {
531
// We don't suggest this since it silences all sorts of warnings, but we
532
// shouldn't blow up either.
533
534
- var child = {
534
+ const child = {
535
$$typeof: <div />.$$typeof,
536
type: 'span',
537
key: null,
@@ -545,7 +545,7 @@ describe('ReactElementValidator', () => {
545
546
it('does not blow up on key warning with undefined type', () => {
547
spyOnDev(console, 'error');
548
- var Foo = undefined;
548
+ const Foo = undefined;
549
void <Foo>{[<div />]}</Foo>;
550
if (__DEV__) {
551
expect(console.error.calls.count()).toBe(1);
packages/react/src/__tests__/ReactJSXElement-test.js
+37
-35
@@ -9,12 +9,12 @@
9
10
'use strict';
11
12
-var React;
13
-var ReactDOM;
14
-var ReactTestUtils;
12
+let React;
13
+let ReactDOM;
14
+let ReactTestUtils;
15
16
describe('ReactJSXElement', () => {
17
- var Component;
17
+ let Component;
18
19
beforeEach(() => {
20
jest.resetModules();
@@ -30,38 +30,38 @@ describe('ReactJSXElement', () => {
30
});
31
32
it('returns a complete element according to spec', () => {
33
- var element = <Component />;
33
+ const element = <Component />;
34
expect(element.type).toBe(Component);
35
expect(element.key).toBe(null);
36
expect(element.ref).toBe(null);
37
- var expectation = {};
37
+ const expectation = {};
38
Object.freeze(expectation);
39
expect(element.props).toEqual(expectation);
40
});
41
42
it('allows a lower-case to be passed as the string type', () => {
43
- var element = <div />;
43
+ const element = <div />;
44
expect(element.type).toBe('div');
45
expect(element.key).toBe(null);
46
expect(element.ref).toBe(null);
47
- var expectation = {};
47
+ const expectation = {};
48
Object.freeze(expectation);
49
expect(element.props).toEqual(expectation);
50
});
51
52
it('allows a string to be passed as the type', () => {
53
- var TagName = 'div';
54
- var element = <TagName />;
53
+ const TagName = 'div';
54
+ const element = <TagName />;
55
expect(element.type).toBe('div');
56
expect(element.key).toBe(null);
57
expect(element.ref).toBe(null);
58
- var expectation = {};
58
+ const expectation = {};
59
Object.freeze(expectation);
60
expect(element.props).toEqual(expectation);
61
});
62
63
it('returns an immutable element', () => {
64
- var element = <Component />;
64
+ const element = <Component />;
65
if (__DEV__) {
66
expect(() => (element.type = 'div')).toThrow();
67
} else {
@@ -70,54 +70,54 @@ describe('ReactJSXElement', () => {
70
});
71
72
it('does not reuse the object that is spread into props', () => {
73
- var config = {foo: 1};
74
- var element = <Component {...config} />;
73
+ const config = {foo: 1};
74
+ const element = <Component {...config} />;
75
expect(element.props.foo).toBe(1);
76
config.foo = 2;
77
expect(element.props.foo).toBe(1);
78
});
79
80
it('extracts key and ref from the rest of the props', () => {
81
- var element = <Component key="12" ref="34" foo="56" />;
81
+ const element = <Component key="12" ref="34" foo="56" />;
82
expect(element.type).toBe(Component);
83
expect(element.key).toBe('12');
84
expect(element.ref).toBe('34');
85
- var expectation = {foo: '56'};
85
+ const expectation = {foo: '56'};
86
Object.freeze(expectation);
87
expect(element.props).toEqual(expectation);
88
});
89
90
it('coerces the key to a string', () => {
91
- var element = <Component key={12} foo="56" />;
91
+ const element = <Component key={12} foo="56" />;
92
expect(element.type).toBe(Component);
93
expect(element.key).toBe('12');
94
expect(element.ref).toBe(null);
95
- var expectation = {foo: '56'};
95
+ const expectation = {foo: '56'};
96
Object.freeze(expectation);
97
expect(element.props).toEqual(expectation);
98
});
99
100
it('merges JSX children onto the children prop', () => {
101
- var a = 1;
102
- var element = <Component children="text">{a}</Component>;
101
+ const a = 1;
102
+ const element = <Component children="text">{a}</Component>;
103
expect(element.props.children).toBe(a);
104
});
105
106
it('does not override children if no JSX children are provided', () => {
107
- var element = <Component children="text" />;
107
+ const element = <Component children="text" />;
108
expect(element.props.children).toBe('text');
109
});
110
111
it('overrides children if null is provided as a JSX child', () => {
112
- var element = <Component children="text">{null}</Component>;
112
+ const element = <Component children="text">{null}</Component>;
113
expect(element.props.children).toBe(null);
114
});
115
116
it('overrides children if undefined is provided as an argument', () => {
117
- var element = <Component children="text">{undefined}</Component>;
117
+ const element = <Component children="text">{undefined}</Component>;
118
expect(element.props.children).toBe(undefined);
119
120
- var element2 = React.cloneElement(
120
+ const element2 = React.cloneElement(
121
<Component children="text" />,
122
{},
123
undefined,
@@ -126,10 +126,10 @@ describe('ReactJSXElement', () => {
126
});
127
128
it('merges JSX children onto the children prop in an array', () => {
129
- var a = 1;
130
- var b = 2;
131
- var c = 3;
132
- var element = (
129
+ const a = 1;
130
+ const b = 2;
131
+ const c = 3;
132
+ const element = (
133
<Component>
134
{a}
135
{b}
@@ -149,7 +149,7 @@ describe('ReactJSXElement', () => {
149
}
150
}
151
152
- var element = <StaticMethodComponent />;
152
+ const element = <StaticMethodComponent />;
153
expect(element.type.someStaticMethod()).toBe('someReturnValue');
154
});
155
@@ -166,16 +166,16 @@ describe('ReactJSXElement', () => {
166
});
167
168
it('is indistinguishable from a plain object', () => {
169
- var element = <div className="foo" />;
170
- var object = {};
169
+ const element = <div className="foo" />;
170
+ const object = {};
171
expect(element.constructor).toBe(object.constructor);
172
});
173
174
it('should use default prop value when removing a prop', () => {
175
Component.defaultProps = {fruit: 'persimmon'};
176
177
- var container = document.createElement('div');
178
- var instance = ReactDOM.render(<Component fruit="mango" />, container);
177
+ const container = document.createElement('div');
178
+ const instance = ReactDOM.render(<Component fruit="mango" />, container);
179
expect(instance.props.fruit).toBe('mango');
180
181
ReactDOM.render(<Component />, container);
@@ -190,10 +190,12 @@ describe('ReactJSXElement', () => {
190
}
191
NormalizingComponent.defaultProps = {prop: 'testKey'};
192
193
- var instance = ReactTestUtils.renderIntoDocument(<NormalizingComponent />);
193
+ const instance = ReactTestUtils.renderIntoDocument(
194
+ <NormalizingComponent />,
195
+ );
196
expect(instance.props.prop).toBe('testKey');
197
196
- var inst2 = ReactTestUtils.renderIntoDocument(
198
+ const inst2 = ReactTestUtils.renderIntoDocument(
199
<NormalizingComponent prop={null} />,
200
);
201
expect(inst2.props.prop).toBe(null);
packages/react/src/__tests__/ReactJSXElementValidator-test.js
+20
-20
@@ -11,18 +11,18 @@
11
12
// TODO: All these warnings should become static errors using Flow instead
13
// of dynamic errors when using JSX with Flow.
14
-var React;
15
-var ReactDOM;
16
-var ReactTestUtils;
17
-var PropTypes;
14
+let React;
15
+let ReactDOM;
16
+let ReactTestUtils;
17
+let PropTypes;
18
19
describe('ReactJSXElementValidator', () => {
20
function normalizeCodeLocInfo(str) {
21
return str && str.replace(/at .+?:\d+/g, 'at **');
22
}
23
24
- var Component;
25
- var RequiredPropComponent;
24
+ let Component;
25
+ let RequiredPropComponent;
26
27
beforeEach(() => {
28
jest.resetModules();
@@ -92,12 +92,12 @@ describe('ReactJSXElementValidator', () => {
92
it('warns for keys for iterables of elements in rest args', () => {
93
spyOnDev(console, 'error');
94
95
- var iterable = {
95
+ const iterable = {
96
'@@iterator': function() {
97
- var i = 0;
97
+ let i = 0;
98
return {
99
next: function() {
100
- var done = ++i > 2;
100
+ const done = ++i > 2;
101
return {value: done ? undefined : <Component />, done: done};
102
},
103
};
@@ -121,12 +121,12 @@ describe('ReactJSXElementValidator', () => {
121
});
122
123
it('does not warn for iterable elements with keys', () => {
124
- var iterable = {
124
+ const iterable = {
125
'@@iterator': function() {
126
- var i = 0;
126
+ let i = 0;
127
return {
128
next: function() {
129
- var done = ++i > 2;
129
+ const done = ++i > 2;
130
return {
131
value: done ? undefined : <Component key={'#' + i} />,
132
done: done,
@@ -140,12 +140,12 @@ describe('ReactJSXElementValidator', () => {
140
});
141
142
it('does not warn for numeric keys in entry iterable as a child', () => {
143
- var iterable = {
143
+ const iterable = {
144
'@@iterator': function() {
145
- var i = 0;
145
+ let i = 0;
146
return {
147
next: function() {
148
- var done = ++i > 2;
148
+ const done = ++i > 2;
149
return {value: done ? undefined : [i, <Component />], done: done};
150
},
151
};
@@ -219,7 +219,7 @@ describe('ReactJSXElementValidator', () => {
219
return React.createElement(MiddleComp, {color: 'blue'});
220
}
221
222
- var container = document.createElement('div');
222
+ const container = document.createElement('div');
223
ReactDOM.render(<ParentComp warn={false} />, container);
224
ReactDOM.render(<ParentComp warn={true} />, container);
225
@@ -239,10 +239,10 @@ describe('ReactJSXElementValidator', () => {
239
});
240
241
it('gives a helpful error when passing null, undefined, or boolean', () => {
242
- var Undefined = undefined;
243
- var Null = null;
244
- var True = true;
245
- var Div = 'div';
242
+ const Undefined = undefined;
243
+ const Null = null;
244
+ const True = true;
245
+ const Div = 'div';
246
spyOnDev(console, 'error');
247
void <Undefined />;
248
void <Null />;
packages/react/src/__tests__/ReactPureComponent-test.js
+10
-10
@@ -9,8 +9,8 @@
9
10
'use strict';
11
12
-var React;
13
-var ReactDOM;
12
+let React;
13
+let ReactDOM;
14
15
describe('ReactPureComponent', () => {
16
beforeEach(() => {
@@ -19,7 +19,7 @@ describe('ReactPureComponent', () => {
19
});
20
21
it('should render', () => {
22
- var renders = 0;
22
+ let renders = 0;
23
class Component extends React.PureComponent {
24
constructor() {
25
super();
@@ -31,9 +31,9 @@ describe('ReactPureComponent', () => {
31
}
32
}
33
34
- var container = document.createElement('div');
35
- var text;
36
- var component;
34
+ const container = document.createElement('div');
35
+ let text;
36
+ let component;
37
38
text = ['porcini'];
39
component = ReactDOM.render(<Component text={text} />, container);
@@ -63,7 +63,7 @@ describe('ReactPureComponent', () => {
63
64
it('can override shouldComponentUpdate', () => {
65
spyOnDev(console, 'error');
66
- var renders = 0;
66
+ let renders = 0;
67
class Component extends React.PureComponent {
68
render() {
69
renders++;
@@ -73,7 +73,7 @@ describe('ReactPureComponent', () => {
73
return true;
74
}
75
}
76
- var container = document.createElement('div');
76
+ const container = document.createElement('div');
77
ReactDOM.render(<Component />, container);
78
ReactDOM.render(<Component />, container);
79
if (__DEV__) {
@@ -89,7 +89,7 @@ describe('ReactPureComponent', () => {
89
});
90
91
it('extends React.Component', () => {
92
- var renders = 0;
92
+ let renders = 0;
93
class Component extends React.PureComponent {
94
render() {
95
expect(this instanceof React.Component).toBe(true);
@@ -113,7 +113,7 @@ describe('ReactPureComponent', () => {
113
return <div />;
114
}
115
}
116
- var container = document.createElement('div');
116
+ const container = document.createElement('div');
117
ReactDOM.render(<PureComponent />, container);
118
119
if (__DEV__) {
packages/react/src/__tests__/createReactClassIntegration-test.js
+25
-25
@@ -9,11 +9,11 @@
9
10
'use strict';
11
12
-var PropTypes;
13
-var React;
14
-var ReactDOM;
15
-var ReactTestUtils;
16
-var createReactClass;
12
+let PropTypes;
13
+let React;
14
+let ReactDOM;
15
+let ReactTestUtils;
16
+let createReactClass;
17
18
describe('create-react-class-integration', () => {
19
beforeEach(() => {
@@ -37,8 +37,8 @@ describe('create-react-class-integration', () => {
37
});
38
39
it('should copy prop types onto the Constructor', () => {
40
- var propValidator = jest.fn();
41
- var TestComponent = createReactClass({
40
+ const propValidator = jest.fn();
41
+ const TestComponent = createReactClass({
42
propTypes: {
43
value: propValidator,
44
},
@@ -233,7 +233,7 @@ describe('create-react-class-integration', () => {
233
});
234
235
it('should support statics', () => {
236
- var Component = createReactClass({
236
+ const Component = createReactClass({
237
statics: {
238
abc: 'def',
239
def: 0,
@@ -248,7 +248,7 @@ describe('create-react-class-integration', () => {
248
return <span />;
249
},
250
});
251
- var instance = <Component />;
251
+ let instance = <Component />;
252
instance = ReactTestUtils.renderIntoDocument(instance);
253
expect(instance.constructor.abc).toBe('def');
254
expect(Component.abc).toBe('def');
@@ -263,7 +263,7 @@ describe('create-react-class-integration', () => {
263
});
264
265
it('should work with object getInitialState() return values', () => {
266
- var Component = createReactClass({
266
+ const Component = createReactClass({
267
getInitialState: function() {
268
return {
269
occupation: 'clown',
@@ -273,13 +273,13 @@ describe('create-react-class-integration', () => {
273
return <span />;
274
},
275
});
276
- var instance = <Component />;
276
+ let instance = <Component />;
277
instance = ReactTestUtils.renderIntoDocument(instance);
278
expect(instance.state.occupation).toEqual('clown');
279
});
280
281
it('renders based on context getInitialState', () => {
282
- var Foo = createReactClass({
282
+ const Foo = createReactClass({
283
contextTypes: {
284
className: PropTypes.string,
285
},
@@ -291,7 +291,7 @@ describe('create-react-class-integration', () => {
291
},
292
});
293
294
- var Outer = createReactClass({
294
+ const Outer = createReactClass({
295
childContextTypes: {
296
className: PropTypes.string,
297
},
@@ -303,14 +303,14 @@ describe('create-react-class-integration', () => {
303
},
304
});
305
306
- var container = document.createElement('div');
306
+ const container = document.createElement('div');
307
ReactDOM.render(<Outer />, container);
308
expect(container.firstChild.className).toBe('foo');
309
});
310
311
it('should throw with non-object getInitialState() return values', () => {
312
[['an array'], 'a string', 1234].forEach(function(state) {
313
- var Component = createReactClass({
313
+ const Component = createReactClass({
314
getInitialState: function() {
315
return state;
316
},
@@ -318,7 +318,7 @@ describe('create-react-class-integration', () => {
318
return <span />;
319
},
320
});
321
- var instance = <Component />;
321
+ let instance = <Component />;
322
expect(function() {
323
instance = ReactTestUtils.renderIntoDocument(instance);
324
}).toThrowError(
@@ -328,7 +328,7 @@ describe('create-react-class-integration', () => {
328
});
329
330
it('should work with a null getInitialState() return value', () => {
331
- var Component = createReactClass({
331
+ const Component = createReactClass({
332
getInitialState: function() {
333
return null;
334
},
@@ -343,7 +343,7 @@ describe('create-react-class-integration', () => {
343
344
it('should throw when using legacy factories', () => {
345
spyOnDev(console, 'error');
346
- var Component = createReactClass({
346
+ const Component = createReactClass({
347
render() {
348
return <div />;
349
},
@@ -360,8 +360,8 @@ describe('create-react-class-integration', () => {
360
});
361
362
it('replaceState and callback works', () => {
363
- var ops = [];
364
- var Component = createReactClass({
363
+ const ops = [];
364
+ const Component = createReactClass({
365
getInitialState() {
366
return {step: 0};
367
},
@@ -371,7 +371,7 @@ describe('create-react-class-integration', () => {
371
},
372
});
373
374
- var instance = ReactTestUtils.renderIntoDocument(<Component />);
374
+ const instance = ReactTestUtils.renderIntoDocument(<Component />);
375
instance.replaceState({step: 1}, () => {
376
ops.push('Callback: ' + instance.state.step);
377
});
@@ -381,9 +381,9 @@ describe('create-react-class-integration', () => {
381
it('isMounted works', () => {
382
spyOnDev(console, 'error');
383
384
- var ops = [];
385
- var instance;
386
- var Component = createReactClass({
384
+ const ops = [];
385
+ let instance;
386
+ const Component = createReactClass({
387
displayName: 'MyComponent',
388
mixins: [
389
{
@@ -433,7 +433,7 @@ describe('create-react-class-integration', () => {
433
},
434
});
435
436
- var container = document.createElement('div');
436
+ const container = document.createElement('div');
437
ReactDOM.render(<Component />, container);
438
ReactDOM.render(<Component />, container);
439
ReactDOM.unmountComponentAtNode(container);
packages/react/src/__tests__/onlyChild-test.js
+8
-8
@@ -10,8 +10,8 @@
10
'use strict';
11
12
describe('onlyChild', () => {
13
- var React;
14
- var WrapComponent;
13
+ let React;
14
+ let WrapComponent;
15
16
beforeEach(() => {
17
React = require('react');
@@ -28,7 +28,7 @@ describe('onlyChild', () => {
28
29
it('should fail when passed two children', () => {
30
expect(function() {
31
- var instance = (
31
+ const instance = (
32
<WrapComponent>
33
<div />
34
<span />
@@ -40,32 +40,32 @@ describe('onlyChild', () => {
40
41
it('should fail when passed nully values', () => {
42
expect(function() {
43
- var instance = <WrapComponent>{null}</WrapComponent>;
43
+ const instance = <WrapComponent>{null}</WrapComponent>;
44
React.Children.only(instance.props.children);
45
}).toThrow();
46
47
expect(function() {
48
- var instance = <WrapComponent>{undefined}</WrapComponent>;
48
+ const instance = <WrapComponent>{undefined}</WrapComponent>;
49
React.Children.only(instance.props.children);
50
}).toThrow();
51
});
52
53
it('should fail when key/value objects', () => {
54
expect(function() {
55
- var instance = <WrapComponent>{[<span key="abc" />]}</WrapComponent>;
55
+ const instance = <WrapComponent>{[<span key="abc" />]}</WrapComponent>;
56
React.Children.only(instance.props.children);
57
}).toThrow();
58
});
59
60
it('should not fail when passed interpolated single child', () => {
61
expect(function() {
62
- var instance = <WrapComponent>{<span />}</WrapComponent>;
62
+ const instance = <WrapComponent>{<span />}</WrapComponent>;
63
React.Children.only(instance.props.children);
64
}).not.toThrow();
65
});
66
67
it('should return the only child', () => {
68
- var instance = (
68
+ const instance = (
69
<WrapComponent>
70
<span />
71
</WrapComponent>