react-test-renderer 16.4.0-alpha.3174632 → 16.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/cjs/react-test-renderer-shallow.development.js +69 -218
- package/cjs/react-test-renderer-shallow.production.min.js +17 -16
- package/cjs/react-test-renderer.development.js +5245 -5035
- package/cjs/react-test-renderer.production.min.js +113 -126
- package/package.json +6 -4
- package/umd/react-test-renderer-shallow.development.js +762 -0
- package/umd/react-test-renderer-shallow.production.min.js +22 -0
- package/umd/react-test-renderer.development.js +9666 -0
- package/umd/react-test-renderer.production.min.js +100 -0
package/README.md
CHANGED
|
@@ -4,6 +4,10 @@ This package provides an experimental React renderer that can be used to render
|
|
|
4
4
|
|
|
5
5
|
Essentially, this package makes it easy to grab a snapshot of the "DOM tree" rendered by a React DOM or React Native component without using a browser or jsdom.
|
|
6
6
|
|
|
7
|
+
Documentation:
|
|
8
|
+
|
|
9
|
+
[https://reactjs.org/docs/test-renderer.html](https://reactjs.org/docs/test-renderer.html)
|
|
10
|
+
|
|
7
11
|
Usage:
|
|
8
12
|
|
|
9
13
|
```jsx
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license React v16.4.
|
|
1
|
+
/** @license React v16.4.2
|
|
2
2
|
* react-test-renderer-shallow.development.js
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
@@ -16,50 +16,15 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
var _assign = require('object-assign');
|
|
19
|
-
var React = require('react');
|
|
20
19
|
var invariant = require('fbjs/lib/invariant');
|
|
20
|
+
var React = require('react');
|
|
21
|
+
var reactIs = require('react-is');
|
|
21
22
|
var emptyObject = require('fbjs/lib/emptyObject');
|
|
22
23
|
var shallowEqual = require('fbjs/lib/shallowEqual');
|
|
23
24
|
var checkPropTypes = require('prop-types/checkPropTypes');
|
|
24
|
-
var warning = require('fbjs/lib/warning');
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* WARNING: DO NOT manually require this module.
|
|
28
|
-
* This is a replacement for `invariant(...)` used by the error code system
|
|
29
|
-
* and will _only_ be required by the corresponding babel pass.
|
|
30
|
-
* It always throws.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
// Exports ReactDOM.createRoot
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// Mutating mode (React DOM, React ART, React Native):
|
|
38
|
-
|
|
39
|
-
// Experimental noop mode (currently unused):
|
|
40
|
-
|
|
41
|
-
// Experimental persistent mode (Fabric):
|
|
42
|
-
|
|
43
|
-
// Experimental error-boundary API that can recover from errors within a single
|
|
44
|
-
// render phase
|
|
45
|
-
|
|
46
|
-
// Helps identify side effects in begin-phase lifecycle hooks and setState reducers:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// In some cases, StrictMode should also double-render lifecycles.
|
|
50
|
-
// This can be confusing for tests though,
|
|
51
|
-
// And it can be bad for performance in production.
|
|
52
|
-
// This feature flag can be used to control the behavior:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// To preserve the "Pause on caught exceptions" behavior of the debugger, we
|
|
56
|
-
// replay the begin phase of a failed component inside invokeGuardedCallback.
|
|
57
25
|
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
var warnAboutDeprecatedLifecycles = false;
|
|
61
|
-
|
|
62
|
-
// Only used in www builds.
|
|
26
|
+
// Relying on the `invariant()` implementation lets us
|
|
27
|
+
// have preserve the format and params in the www builds.
|
|
63
28
|
|
|
64
29
|
var describeComponentFrame = function (name, source, ownerName) {
|
|
65
30
|
return '\n in ' + (name || 'Unknown') + (source ? ' (at ' + source.fileName.replace(/^.*[\\\/]/, '') + ':' + source.lineNumber + ')' : ownerName ? ' (created by ' + ownerName + ')' : '');
|
|
@@ -67,13 +32,18 @@ var describeComponentFrame = function (name, source, ownerName) {
|
|
|
67
32
|
|
|
68
33
|
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
|
|
69
34
|
// nor polyfill, then a plain number is used for performance.
|
|
70
|
-
var hasSymbol = typeof Symbol === 'function' && Symbol
|
|
35
|
+
var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
|
71
36
|
|
|
72
37
|
|
|
73
|
-
var
|
|
74
|
-
var
|
|
75
|
-
var
|
|
76
|
-
var
|
|
38
|
+
var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
|
|
39
|
+
var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
|
|
40
|
+
var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
|
|
41
|
+
var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
|
|
42
|
+
var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
|
|
43
|
+
var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
|
|
44
|
+
var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
|
|
45
|
+
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
|
|
46
|
+
var REACT_TIMEOUT_TYPE = hasSymbol ? Symbol.for('react.timeout') : 0xead1;
|
|
77
47
|
|
|
78
48
|
function getComponentName(fiber) {
|
|
79
49
|
var type = fiber.type;
|
|
@@ -85,91 +55,35 @@ function getComponentName(fiber) {
|
|
|
85
55
|
return type;
|
|
86
56
|
}
|
|
87
57
|
switch (type) {
|
|
58
|
+
case REACT_ASYNC_MODE_TYPE:
|
|
59
|
+
return 'AsyncMode';
|
|
60
|
+
case REACT_CONTEXT_TYPE:
|
|
61
|
+
return 'Context.Consumer';
|
|
88
62
|
case REACT_FRAGMENT_TYPE:
|
|
89
63
|
return 'ReactFragment';
|
|
90
64
|
case REACT_PORTAL_TYPE:
|
|
91
65
|
return 'ReactPortal';
|
|
92
|
-
case
|
|
93
|
-
return '
|
|
94
|
-
case
|
|
95
|
-
return '
|
|
66
|
+
case REACT_PROFILER_TYPE:
|
|
67
|
+
return 'Profiler(' + fiber.pendingProps.id + ')';
|
|
68
|
+
case REACT_PROVIDER_TYPE:
|
|
69
|
+
return 'Context.Provider';
|
|
70
|
+
case REACT_STRICT_MODE_TYPE:
|
|
71
|
+
return 'StrictMode';
|
|
72
|
+
case REACT_TIMEOUT_TYPE:
|
|
73
|
+
return 'Timeout';
|
|
96
74
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
* https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
|
|
103
|
-
*
|
|
104
|
-
* Only change is we use console.warn instead of console.error,
|
|
105
|
-
* and do nothing when 'console' is not supported.
|
|
106
|
-
* This really simplifies the code.
|
|
107
|
-
* ---
|
|
108
|
-
* Similar to invariant but only logs a warning if the condition is not met.
|
|
109
|
-
* This can be used to log issues in development environments in critical
|
|
110
|
-
* paths. Removing the logging code for production environments will keep the
|
|
111
|
-
* same logic and follow the same code paths.
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
var lowPriorityWarning = function () {};
|
|
115
|
-
|
|
116
|
-
{
|
|
117
|
-
var printWarning = function (format) {
|
|
118
|
-
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
119
|
-
args[_key - 1] = arguments[_key];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
var argIndex = 0;
|
|
123
|
-
var message = 'Warning: ' + format.replace(/%s/g, function () {
|
|
124
|
-
return args[argIndex++];
|
|
125
|
-
});
|
|
126
|
-
if (typeof console !== 'undefined') {
|
|
127
|
-
console.warn(message);
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
// --- Welcome to debugging React ---
|
|
131
|
-
// This error was thrown as a convenience so that you can use this stack
|
|
132
|
-
// to find the callsite that caused this warning to fire.
|
|
133
|
-
throw new Error(message);
|
|
134
|
-
} catch (x) {}
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
lowPriorityWarning = function (condition, format) {
|
|
138
|
-
if (format === undefined) {
|
|
139
|
-
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
|
|
140
|
-
}
|
|
141
|
-
if (!condition) {
|
|
142
|
-
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
143
|
-
args[_key2 - 2] = arguments[_key2];
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
printWarning.apply(undefined, [format].concat(args));
|
|
75
|
+
if (typeof type === 'object' && type !== null) {
|
|
76
|
+
switch (type.$$typeof) {
|
|
77
|
+
case REACT_FORWARD_REF_TYPE:
|
|
78
|
+
var functionName = type.render.displayName || type.render.name || '';
|
|
79
|
+
return functionName !== '' ? 'ForwardRef(' + functionName + ')' : 'ForwardRef';
|
|
147
80
|
}
|
|
148
|
-
}
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
149
83
|
}
|
|
150
84
|
|
|
151
|
-
var lowPriorityWarning$1 = lowPriorityWarning;
|
|
152
|
-
|
|
153
85
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
154
86
|
|
|
155
|
-
var didWarnAboutLegacyWillMount = void 0;
|
|
156
|
-
var didWarnAboutLegacyWillReceiveProps = void 0;
|
|
157
|
-
var didWarnAboutLegacyWillUpdate = void 0;
|
|
158
|
-
var didWarnAboutUndefinedDerivedState = void 0;
|
|
159
|
-
var didWarnAboutUninitializedState = void 0;
|
|
160
|
-
var didWarnAboutWillReceivePropsAndDerivedState = void 0;
|
|
161
|
-
|
|
162
|
-
{
|
|
163
|
-
if (warnAboutDeprecatedLifecycles) {
|
|
164
|
-
didWarnAboutLegacyWillMount = {};
|
|
165
|
-
didWarnAboutLegacyWillReceiveProps = {};
|
|
166
|
-
didWarnAboutLegacyWillUpdate = {};
|
|
167
|
-
}
|
|
168
|
-
didWarnAboutUndefinedDerivedState = {};
|
|
169
|
-
didWarnAboutUninitializedState = {};
|
|
170
|
-
didWarnAboutWillReceivePropsAndDerivedState = {};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
87
|
var ReactShallowRenderer = function () {
|
|
174
88
|
function ReactShallowRenderer() {
|
|
175
89
|
_classCallCheck(this, ReactShallowRenderer);
|
|
@@ -198,7 +112,7 @@ var ReactShallowRenderer = function () {
|
|
|
198
112
|
!React.isValidElement(element) ? invariant(false, 'ReactShallowRenderer render(): Invalid component element.%s', typeof element === 'function' ? ' Instead of passing a component class, make sure to instantiate ' + 'it by passing it to React.createElement.' : '') : void 0;
|
|
199
113
|
// Show a special message for host elements since it's a common case.
|
|
200
114
|
!(typeof element.type !== 'string') ? invariant(false, 'ReactShallowRenderer render(): Shallow rendering works only with custom components, not primitives (%s). Instead of calling `.render(el)` and inspecting the rendered output, look at `el.props` directly instead.', element.type) : void 0;
|
|
201
|
-
!(typeof element.type === 'function') ? invariant(false, 'ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `%s`.', Array.isArray(element.type) ? 'array' : element.type === null ? 'null' : typeof element.type) : void 0;
|
|
115
|
+
!(reactIs.isForwardRef(element) || typeof element.type === 'function') ? invariant(false, 'ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `%s`.', Array.isArray(element.type) ? 'array' : element.type === null ? 'null' : typeof element.type) : void 0;
|
|
202
116
|
|
|
203
117
|
if (this._rendering) {
|
|
204
118
|
return;
|
|
@@ -211,21 +125,11 @@ var ReactShallowRenderer = function () {
|
|
|
211
125
|
if (this._instance) {
|
|
212
126
|
this._updateClassComponent(element, this._context);
|
|
213
127
|
} else {
|
|
214
|
-
if (
|
|
128
|
+
if (reactIs.isForwardRef(element)) {
|
|
129
|
+
this._rendered = element.type.render(element.props, element.ref);
|
|
130
|
+
} else if (shouldConstruct(element.type)) {
|
|
215
131
|
this._instance = new element.type(element.props, this._context, this._updater);
|
|
216
132
|
|
|
217
|
-
{
|
|
218
|
-
if (typeof element.type.getDerivedStateFromProps === 'function') {
|
|
219
|
-
if (this._instance.state === null || this._instance.state === undefined) {
|
|
220
|
-
var componentName = getName(element.type, this._instance) || 'Unknown';
|
|
221
|
-
if (!didWarnAboutUninitializedState[componentName]) {
|
|
222
|
-
warning(false, '%s: Did not properly initialize state during construction. ' + 'Expected state to be an object, but it was %s.', componentName, this._instance.state === null ? 'null' : 'undefined');
|
|
223
|
-
didWarnAboutUninitializedState[componentName] = true;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
133
|
this._updateStateFromStaticLifecycle(element.props);
|
|
230
134
|
|
|
231
135
|
if (element.type.hasOwnProperty('contextTypes')) {
|
|
@@ -271,28 +175,15 @@ var ReactShallowRenderer = function () {
|
|
|
271
175
|
if (typeof this._instance.UNSAFE_componentWillMount === 'function' || typeof this._instance.componentWillMount === 'function') {
|
|
272
176
|
var beforeState = this._newState;
|
|
273
177
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
var componentName = getName(element.type, this._instance);
|
|
279
|
-
if (!didWarnAboutLegacyWillMount[componentName]) {
|
|
280
|
-
lowPriorityWarning$1(false, '%s: componentWillMount() is deprecated and will be ' + 'removed in the next major version. Read about the motivations ' + 'behind this change: ' + 'https://fb.me/react-async-component-lifecycle-hooks' + '\n\n' + 'As a temporary workaround, you can rename to ' + 'UNSAFE_componentWillMount instead.', componentName);
|
|
281
|
-
didWarnAboutLegacyWillMount[componentName] = true;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// In order to support react-lifecycles-compat polyfilled components,
|
|
287
|
-
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
|
|
288
|
-
if (typeof element.type.getDerivedStateFromProps !== 'function') {
|
|
178
|
+
// In order to support react-lifecycles-compat polyfilled components,
|
|
179
|
+
// Unsafe lifecycles should not be invoked for components using the new APIs.
|
|
180
|
+
if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
|
|
181
|
+
if (typeof this._instance.componentWillMount === 'function') {
|
|
289
182
|
this._instance.componentWillMount();
|
|
290
183
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
|
|
295
|
-
this._instance.UNSAFE_componentWillMount();
|
|
184
|
+
if (typeof this._instance.UNSAFE_componentWillMount === 'function') {
|
|
185
|
+
this._instance.UNSAFE_componentWillMount();
|
|
186
|
+
}
|
|
296
187
|
}
|
|
297
188
|
|
|
298
189
|
// setState may have been called during cWM
|
|
@@ -315,30 +206,18 @@ var ReactShallowRenderer = function () {
|
|
|
315
206
|
var oldProps = this._instance.props;
|
|
316
207
|
|
|
317
208
|
if (oldProps !== props) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
if (!didWarnAboutLegacyWillReceiveProps[componentName]) {
|
|
323
|
-
lowPriorityWarning$1(false, '%s: componentWillReceiveProps() is deprecated and ' + 'will be removed in the next major version. Use ' + 'static getDerivedStateFromProps() instead. Read about the ' + 'motivations behind this change: ' + 'https://fb.me/react-async-component-lifecycle-hooks' + '\n\n' + 'As a temporary workaround, you can rename to ' + 'UNSAFE_componentWillReceiveProps instead.', componentName);
|
|
324
|
-
didWarnAboutLegacyWillReceiveProps[componentName] = true;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
// In order to support react-lifecycles-compat polyfilled components,
|
|
329
|
-
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
|
|
330
|
-
if (typeof element.type.getDerivedStateFromProps !== 'function') {
|
|
209
|
+
// In order to support react-lifecycles-compat polyfilled components,
|
|
210
|
+
// Unsafe lifecycles should not be invoked for components using the new APIs.
|
|
211
|
+
if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
|
|
212
|
+
if (typeof this._instance.componentWillReceiveProps === 'function') {
|
|
331
213
|
this._instance.componentWillReceiveProps(props, context);
|
|
332
214
|
}
|
|
215
|
+
if (typeof this._instance.UNSAFE_componentWillReceiveProps === 'function') {
|
|
216
|
+
this._instance.UNSAFE_componentWillReceiveProps(props, context);
|
|
217
|
+
}
|
|
333
218
|
}
|
|
334
|
-
if (typeof this._instance.UNSAFE_componentWillReceiveProps === 'function' && typeof element.type.getDerivedStateFromProps !== 'function') {
|
|
335
|
-
// In order to support react-lifecycles-compat polyfilled components,
|
|
336
|
-
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
|
|
337
|
-
this._instance.UNSAFE_componentWillReceiveProps(props, context);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
this._updateStateFromStaticLifecycle(props);
|
|
341
219
|
}
|
|
220
|
+
this._updateStateFromStaticLifecycle(props);
|
|
342
221
|
|
|
343
222
|
// Read state after cWRP in case it calls setState
|
|
344
223
|
var state = this._newState || oldState;
|
|
@@ -354,27 +233,15 @@ var ReactShallowRenderer = function () {
|
|
|
354
233
|
}
|
|
355
234
|
|
|
356
235
|
if (shouldUpdate) {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (!didWarnAboutLegacyWillUpdate[_componentName]) {
|
|
362
|
-
lowPriorityWarning$1(false, '%s: componentWillUpdate() is deprecated and will be ' + 'removed in the next major version. Read about the motivations ' + 'behind this change: ' + 'https://fb.me/react-async-component-lifecycle-hooks' + '\n\n' + 'As a temporary workaround, you can rename to ' + 'UNSAFE_componentWillUpdate instead.', _componentName);
|
|
363
|
-
didWarnAboutLegacyWillUpdate[_componentName] = true;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// In order to support react-lifecycles-compat polyfilled components,
|
|
369
|
-
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
|
|
370
|
-
if (typeof type.getDerivedStateFromProps !== 'function') {
|
|
236
|
+
// In order to support react-lifecycles-compat polyfilled components,
|
|
237
|
+
// Unsafe lifecycles should not be invoked for components using the new APIs.
|
|
238
|
+
if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
|
|
239
|
+
if (typeof this._instance.componentWillUpdate === 'function') {
|
|
371
240
|
this._instance.componentWillUpdate(props, state, context);
|
|
372
241
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
|
|
377
|
-
this._instance.UNSAFE_componentWillUpdate(props, state, context);
|
|
242
|
+
if (typeof this._instance.UNSAFE_componentWillUpdate === 'function') {
|
|
243
|
+
this._instance.UNSAFE_componentWillUpdate(props, state, context);
|
|
244
|
+
}
|
|
378
245
|
}
|
|
379
246
|
}
|
|
380
247
|
|
|
@@ -394,31 +261,10 @@ var ReactShallowRenderer = function () {
|
|
|
394
261
|
|
|
395
262
|
|
|
396
263
|
if (typeof type.getDerivedStateFromProps === 'function') {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
if (typeof this._instance.componentWillReceiveProps === 'function' && this._instance.componentWillReceiveProps.__suppressDeprecationWarning !== true || typeof this._instance.UNSAFE_componentWillReceiveProps === 'function') {
|
|
400
|
-
var componentName = getName(type, this._instance);
|
|
401
|
-
if (!didWarnAboutWillReceivePropsAndDerivedState[componentName]) {
|
|
402
|
-
warning(false, '%s: Defines both componentWillReceiveProps() and static ' + 'getDerivedStateFromProps() methods. We recommend using ' + 'only getDerivedStateFromProps().', componentName);
|
|
403
|
-
didWarnAboutWillReceivePropsAndDerivedState[componentName] = true;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
var partialState = type.getDerivedStateFromProps.call(null, props, this._instance.state);
|
|
409
|
-
|
|
410
|
-
{
|
|
411
|
-
if (partialState === undefined) {
|
|
412
|
-
var _componentName2 = getName(type, this._instance);
|
|
413
|
-
if (!didWarnAboutUndefinedDerivedState[_componentName2]) {
|
|
414
|
-
warning(false, '%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', _componentName2);
|
|
415
|
-
didWarnAboutUndefinedDerivedState[_componentName2] = _componentName2;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
264
|
+
var oldState = this._newState || this._instance.state;
|
|
265
|
+
var partialState = type.getDerivedStateFromProps.call(null, props, oldState);
|
|
419
266
|
|
|
420
267
|
if (partialState != null) {
|
|
421
|
-
var oldState = this._newState || this._instance.state;
|
|
422
268
|
var newState = _assign({}, oldState, partialState);
|
|
423
269
|
this._instance.state = this._newState = newState;
|
|
424
270
|
}
|
|
@@ -482,7 +328,12 @@ var Updater = function () {
|
|
|
482
328
|
var currentState = this._renderer._newState || publicInstance.state;
|
|
483
329
|
|
|
484
330
|
if (typeof partialState === 'function') {
|
|
485
|
-
partialState = partialState(currentState, publicInstance.props);
|
|
331
|
+
partialState = partialState.call(publicInstance, currentState, publicInstance.props);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Null and undefined are treated as no-ops.
|
|
335
|
+
if (partialState === null || partialState === undefined) {
|
|
336
|
+
return;
|
|
486
337
|
}
|
|
487
338
|
|
|
488
339
|
this._renderer._newState = _assign({}, currentState, partialState);
|
|
@@ -547,7 +398,7 @@ var ReactShallowRenderer$3 = ( ReactShallowRenderer$2 && ReactShallowRenderer )
|
|
|
547
398
|
|
|
548
399
|
// TODO: decide on the top-level export form.
|
|
549
400
|
// This is hacky but makes it work with both Rollup and Jest.
|
|
550
|
-
var shallow = ReactShallowRenderer$3
|
|
401
|
+
var shallow = ReactShallowRenderer$3.default ? ReactShallowRenderer$3.default : ReactShallowRenderer$3;
|
|
551
402
|
|
|
552
403
|
module.exports = shallow;
|
|
553
404
|
})();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license React v16.4.
|
|
1
|
+
/** @license React v16.4.2
|
|
2
2
|
* react-test-renderer-shallow.production.min.js
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
@@ -7,18 +7,19 @@
|
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
'use strict';var e=require("object-assign"),
|
|
11
|
-
function
|
|
12
|
-
var
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
a.type
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this._instance.
|
|
20
|
-
|
|
21
|
-
"function"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
'use strict';var e=require("object-assign"),f=require("fbjs/lib/invariant"),l=require("react"),m=require("react-is"),n=require("fbjs/lib/emptyObject"),p=require("fbjs/lib/shallowEqual"),q=require("prop-types/checkPropTypes");
|
|
11
|
+
function r(d){for(var a=arguments.length-1,b="https://reactjs.org/docs/error-decoder.html?invariant="+d,c=0;c<a;c++)b+="&args[]="+encodeURIComponent(arguments[c+1]);f(!1,"Minified React error #"+d+"; visit %s for the full message or use the non-minified dev environment for full errors and additional helpful warnings. ",b)}
|
|
12
|
+
var t="function"===typeof Symbol&&Symbol.for,u=t?Symbol.for("react.portal"):60106,w=t?Symbol.for("react.fragment"):60107,x=t?Symbol.for("react.strict_mode"):60108,y=t?Symbol.for("react.profiler"):60114,z=t?Symbol.for("react.provider"):60109,A=t?Symbol.for("react.context"):60110,B=t?Symbol.for("react.async_mode"):60111,C=t?Symbol.for("react.forward_ref"):60112,D=t?Symbol.for("react.timeout"):60113;
|
|
13
|
+
function E(d){var a=d.type;if("function"===typeof a)return a.displayName||a.name;if("string"===typeof a)return a;switch(a){case B:return"AsyncMode";case A:return"Context.Consumer";case w:return"ReactFragment";case u:return"ReactPortal";case y:return"Profiler("+d.pendingProps.id+")";case z:return"Context.Provider";case x:return"StrictMode";case D:return"Timeout"}if("object"===typeof a&&null!==a)switch(a.$$typeof){case C:return d=a.render.displayName||a.render.name||"",""!==d?"ForwardRef("+d+")":"ForwardRef"}return null}
|
|
14
|
+
function F(d,a){if(!(d instanceof a))throw new TypeError("Cannot call a class as a function");}
|
|
15
|
+
var J=function(){function d(){F(this,d);this._rendered=this._newState=this._instance=this._element=this._context=null;this._forcedUpdate=this._rendering=!1;this._updater=new G(this)}d.prototype.getMountedInstance=function(){return this._instance};d.prototype.getRenderOutput=function(){return this._rendered};d.prototype.render=function(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:n;l.isValidElement(a)?void 0:r("12","function"===typeof a?" Instead of passing a component class, make sure to instantiate it by passing it to React.createElement.":
|
|
16
|
+
"");"string"===typeof a.type?r("13",a.type):void 0;m.isForwardRef(a)||"function"===typeof a.type?void 0:r("249",Array.isArray(a.type)?"array":null===a.type?"null":typeof a.type);if(!this._rendering){this._rendering=!0;this._element=a;var c=a.type.contextTypes;if(c){var d={},g;for(g in c)d[g]=b[g];b=d}else b=n;this._context=b;this._instance?this._updateClassComponent(a,this._context):m.isForwardRef(a)?this._rendered=a.type.render(a.props,a.ref):(b=a.type,b.prototype&&b.prototype.isReactComponent?(this._instance=
|
|
17
|
+
new a.type(a.props,this._context,this._updater),this._updateStateFromStaticLifecycle(a.props),a.type.hasOwnProperty("contextTypes")&&(H=a,b=a.type,c=(c=this._instance)&&c.constructor,q(a.type.contextTypes,this._context,"context",b.displayName||c&&c.displayName||b.name||c&&c.name||null,I),H=null),this._mountClassComponent(a,this._context)):this._rendered=a.type(a.props,this._context));this._rendering=!1;this._updater._invokeCallbacks();return this.getRenderOutput()}};d.prototype.unmount=function(){this._instance&&
|
|
18
|
+
"function"===typeof this._instance.componentWillUnmount&&this._instance.componentWillUnmount();this._instance=this._rendered=this._newState=this._element=this._context=null};d.prototype._mountClassComponent=function(a,b){this._instance.context=b;this._instance.props=a.props;this._instance.state=this._instance.state||null;this._instance.updater=this._updater;if("function"===typeof this._instance.UNSAFE_componentWillMount||"function"===typeof this._instance.componentWillMount)b=this._newState,"function"!==
|
|
19
|
+
typeof a.type.getDerivedStateFromProps&&"function"!==typeof this._instance.getSnapshotBeforeUpdate&&("function"===typeof this._instance.componentWillMount&&this._instance.componentWillMount(),"function"===typeof this._instance.UNSAFE_componentWillMount&&this._instance.UNSAFE_componentWillMount()),b!==this._newState&&(this._instance.state=this._newState||n);this._rendered=this._instance.render()};d.prototype._updateClassComponent=function(a,b){var c=a.props,d=a.type,g=this._instance.state||n,v=this._instance.props;
|
|
20
|
+
v!==c&&"function"!==typeof a.type.getDerivedStateFromProps&&"function"!==typeof this._instance.getSnapshotBeforeUpdate&&("function"===typeof this._instance.componentWillReceiveProps&&this._instance.componentWillReceiveProps(c,b),"function"===typeof this._instance.UNSAFE_componentWillReceiveProps&&this._instance.UNSAFE_componentWillReceiveProps(c,b));this._updateStateFromStaticLifecycle(c);var h=this._newState||g,k=!0;this._forcedUpdate?(k=!0,this._forcedUpdate=!1):"function"===typeof this._instance.shouldComponentUpdate?
|
|
21
|
+
k=!!this._instance.shouldComponentUpdate(c,h,b):d.prototype&&d.prototype.isPureReactComponent&&(k=!p(v,c)||!p(g,h));k&&"function"!==typeof a.type.getDerivedStateFromProps&&"function"!==typeof this._instance.getSnapshotBeforeUpdate&&("function"===typeof this._instance.componentWillUpdate&&this._instance.componentWillUpdate(c,h,b),"function"===typeof this._instance.UNSAFE_componentWillUpdate&&this._instance.UNSAFE_componentWillUpdate(c,h,b));this._instance.context=b;this._instance.props=c;this._instance.state=
|
|
22
|
+
h;k&&(this._rendered=this._instance.render())};d.prototype._updateStateFromStaticLifecycle=function(a){var b=this._element.type;if("function"===typeof b.getDerivedStateFromProps){var c=this._newState||this._instance.state;a=b.getDerivedStateFromProps.call(null,a,c);null!=a&&(c=e({},c,a),this._instance.state=this._newState=c)}};return d}();J.createRenderer=function(){return new J};
|
|
23
|
+
var G=function(){function d(a){F(this,d);this._renderer=a;this._callbacks=[]}d.prototype._enqueueCallback=function(a,b){"function"===typeof a&&b&&this._callbacks.push({callback:a,publicInstance:b})};d.prototype._invokeCallbacks=function(){var a=this._callbacks;this._callbacks=[];a.forEach(function(a){a.callback.call(a.publicInstance)})};d.prototype.isMounted=function(){return!!this._renderer._element};d.prototype.enqueueForceUpdate=function(a,b){this._enqueueCallback(b,a);this._renderer._forcedUpdate=
|
|
24
|
+
!0;this._renderer.render(this._renderer._element,this._renderer._context)};d.prototype.enqueueReplaceState=function(a,b,c){this._enqueueCallback(c,a);this._renderer._newState=b;this._renderer.render(this._renderer._element,this._renderer._context)};d.prototype.enqueueSetState=function(a,b,c){this._enqueueCallback(c,a);c=this._renderer._newState||a.state;"function"===typeof b&&(b=b.call(a,c,a.props));null!==b&&void 0!==b&&(this._renderer._newState=e({},c,b),this._renderer.render(this._renderer._element,
|
|
25
|
+
this._renderer._context))};return d}(),H=null;function I(){var d="";if(H){var a=null==H?"#empty":"string"===typeof H||"number"===typeof H?"#text":"string"===typeof H.type?H.type:H.type.displayName||H.type.name||"Unknown",b=H._owner,c=H._source;b=b&&E(b);a="\n in "+(a||"Unknown")+(c?" (at "+c.fileName.replace(/^.*[\\\/]/,"")+":"+c.lineNumber+")":b?" (created by "+b+")":"");d+=a}return d}var K={default:J},L=K&&J||K;module.exports=L.default?L.default:L;
|