1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | (function (global, factory) {
|
13 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react'), require('react-dom')) :
|
14 | typeof define === 'function' && define.amd ? define(['react', 'react-dom'], factory) :
|
15 | (global.ReactTestUtils = factory(global.React,global.ReactDOM));
|
16 | }(this, (function (React,ReactDOM) { 'use strict';
|
17 |
|
18 | var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
19 | var _assign = ReactInternals.assign;
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | var warningWithoutStack = function () {};
|
43 |
|
44 | {
|
45 | warningWithoutStack = function (condition, format) {
|
46 | for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
47 | args[_key - 2] = arguments[_key];
|
48 | }
|
49 |
|
50 | if (format === undefined) {
|
51 | throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
|
52 | }
|
53 |
|
54 | if (args.length > 8) {
|
55 |
|
56 | throw new Error('warningWithoutStack() currently supports at most 8 arguments.');
|
57 | }
|
58 |
|
59 | if (condition) {
|
60 | return;
|
61 | }
|
62 |
|
63 | if (typeof console !== 'undefined') {
|
64 | var argsWithFormat = args.map(function (item) {
|
65 | return '' + item;
|
66 | });
|
67 | argsWithFormat.unshift('Warning: ' + format);
|
68 |
|
69 |
|
70 | Function.prototype.apply.call(console.error, console, argsWithFormat);
|
71 | }
|
72 |
|
73 | try {
|
74 |
|
75 |
|
76 |
|
77 | var argIndex = 0;
|
78 | var message = 'Warning: ' + format.replace(/%s/g, function () {
|
79 | return args[argIndex++];
|
80 | });
|
81 | throw new Error(message);
|
82 | } catch (x) {}
|
83 | };
|
84 | }
|
85 |
|
86 | var warningWithoutStack$1 = warningWithoutStack;
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | function get(key) {
|
105 | return key._reactInternalFiber;
|
106 | }
|
107 |
|
108 | var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
109 |
|
110 |
|
111 |
|
112 | if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
|
113 | ReactSharedInternals.ReactCurrentDispatcher = {
|
114 | current: null
|
115 | };
|
116 | }
|
117 |
|
118 | if (!ReactSharedInternals.hasOwnProperty('ReactCurrentBatchConfig')) {
|
119 | ReactSharedInternals.ReactCurrentBatchConfig = {
|
120 | suspense: null
|
121 | };
|
122 | }
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 | {
|
136 |
|
137 | }
|
138 |
|
139 | var FunctionComponent = 0;
|
140 | var ClassComponent = 1;
|
141 |
|
142 |
|
143 | var HostRoot = 3;
|
144 |
|
145 |
|
146 |
|
147 | var HostComponent = 5;
|
148 | var HostText = 6;
|
149 |
|
150 |
|
151 | var NoEffect =
|
152 |
|
153 | 0;
|
154 |
|
155 |
|
156 | var Placement =
|
157 |
|
158 | 2;
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | var Hydrating =
|
169 |
|
170 | 1024;
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 | var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
|
234 | function getNearestMountedFiber(fiber) {
|
235 | var node = fiber;
|
236 | var nearestMounted = fiber;
|
237 |
|
238 | if (!fiber.alternate) {
|
239 |
|
240 |
|
241 | var nextNode = node;
|
242 |
|
243 | do {
|
244 | node = nextNode;
|
245 |
|
246 | if ((node.effectTag & (Placement | Hydrating)) !== NoEffect) {
|
247 |
|
248 |
|
249 |
|
250 | nearestMounted = node.return;
|
251 | }
|
252 |
|
253 | nextNode = node.return;
|
254 | } while (nextNode);
|
255 | } else {
|
256 | while (node.return) {
|
257 | node = node.return;
|
258 | }
|
259 | }
|
260 |
|
261 | if (node.tag === HostRoot) {
|
262 |
|
263 |
|
264 | return nearestMounted;
|
265 | }
|
266 |
|
267 |
|
268 |
|
269 | return null;
|
270 | }
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 | function assertIsMounted(fiber) {
|
277 | if (!(getNearestMountedFiber(fiber) === fiber)) {
|
278 | {
|
279 | throw Error("Unable to find node on an unmounted component.");
|
280 | }
|
281 | }
|
282 | }
|
283 |
|
284 | function findCurrentFiberUsingSlowPath(fiber) {
|
285 | var alternate = fiber.alternate;
|
286 |
|
287 | if (!alternate) {
|
288 |
|
289 | var nearestMounted = getNearestMountedFiber(fiber);
|
290 |
|
291 | if (!(nearestMounted !== null)) {
|
292 | {
|
293 | throw Error("Unable to find node on an unmounted component.");
|
294 | }
|
295 | }
|
296 |
|
297 | if (nearestMounted !== fiber) {
|
298 | return null;
|
299 | }
|
300 |
|
301 | return fiber;
|
302 | }
|
303 |
|
304 |
|
305 |
|
306 |
|
307 | var a = fiber;
|
308 | var b = alternate;
|
309 |
|
310 | while (true) {
|
311 | var parentA = a.return;
|
312 |
|
313 | if (parentA === null) {
|
314 |
|
315 | break;
|
316 | }
|
317 |
|
318 | var parentB = parentA.alternate;
|
319 |
|
320 | if (parentB === null) {
|
321 |
|
322 |
|
323 |
|
324 |
|
325 | var nextParent = parentA.return;
|
326 |
|
327 | if (nextParent !== null) {
|
328 | a = b = nextParent;
|
329 | continue;
|
330 | }
|
331 |
|
332 |
|
333 | break;
|
334 | }
|
335 |
|
336 |
|
337 |
|
338 |
|
339 | if (parentA.child === parentB.child) {
|
340 | var child = parentA.child;
|
341 |
|
342 | while (child) {
|
343 | if (child === a) {
|
344 |
|
345 | assertIsMounted(parentA);
|
346 | return fiber;
|
347 | }
|
348 |
|
349 | if (child === b) {
|
350 |
|
351 | assertIsMounted(parentA);
|
352 | return alternate;
|
353 | }
|
354 |
|
355 | child = child.sibling;
|
356 | }
|
357 |
|
358 |
|
359 |
|
360 | {
|
361 | {
|
362 | throw Error("Unable to find node on an unmounted component.");
|
363 | }
|
364 | }
|
365 | }
|
366 |
|
367 | if (a.return !== b.return) {
|
368 |
|
369 |
|
370 |
|
371 |
|
372 | a = parentA;
|
373 | b = parentB;
|
374 | } else {
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 | var didFindChild = false;
|
381 | var _child = parentA.child;
|
382 |
|
383 | while (_child) {
|
384 | if (_child === a) {
|
385 | didFindChild = true;
|
386 | a = parentA;
|
387 | b = parentB;
|
388 | break;
|
389 | }
|
390 |
|
391 | if (_child === b) {
|
392 | didFindChild = true;
|
393 | b = parentA;
|
394 | a = parentB;
|
395 | break;
|
396 | }
|
397 |
|
398 | _child = _child.sibling;
|
399 | }
|
400 |
|
401 | if (!didFindChild) {
|
402 |
|
403 | _child = parentB.child;
|
404 |
|
405 | while (_child) {
|
406 | if (_child === a) {
|
407 | didFindChild = true;
|
408 | a = parentB;
|
409 | b = parentA;
|
410 | break;
|
411 | }
|
412 |
|
413 | if (_child === b) {
|
414 | didFindChild = true;
|
415 | b = parentB;
|
416 | a = parentA;
|
417 | break;
|
418 | }
|
419 |
|
420 | _child = _child.sibling;
|
421 | }
|
422 |
|
423 | if (!didFindChild) {
|
424 | {
|
425 | throw Error("Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue.");
|
426 | }
|
427 | }
|
428 | }
|
429 | }
|
430 |
|
431 | if (!(a.alternate === b)) {
|
432 | {
|
433 | throw Error("Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue.");
|
434 | }
|
435 | }
|
436 | }
|
437 |
|
438 |
|
439 |
|
440 | if (!(a.tag === HostRoot)) {
|
441 | {
|
442 | throw Error("Unable to find node on an unmounted component.");
|
443 | }
|
444 | }
|
445 |
|
446 | if (a.stateNode.current === a) {
|
447 |
|
448 | return fiber;
|
449 | }
|
450 |
|
451 |
|
452 | return alternate;
|
453 | }
|
454 |
|
455 |
|
456 | var EVENT_POOL_SIZE = 10;
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 | var EventInterface = {
|
463 | type: null,
|
464 | target: null,
|
465 |
|
466 | currentTarget: function () {
|
467 | return null;
|
468 | },
|
469 | eventPhase: null,
|
470 | bubbles: null,
|
471 | cancelable: null,
|
472 | timeStamp: function (event) {
|
473 | return event.timeStamp || Date.now();
|
474 | },
|
475 | defaultPrevented: null,
|
476 | isTrusted: null
|
477 | };
|
478 |
|
479 | function functionThatReturnsTrue() {
|
480 | return true;
|
481 | }
|
482 |
|
483 | function functionThatReturnsFalse() {
|
484 | return false;
|
485 | }
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 | function SyntheticEvent(dispatchConfig, targetInst, nativeEvent, nativeEventTarget) {
|
507 | {
|
508 |
|
509 | delete this.nativeEvent;
|
510 | delete this.preventDefault;
|
511 | delete this.stopPropagation;
|
512 | delete this.isDefaultPrevented;
|
513 | delete this.isPropagationStopped;
|
514 | }
|
515 |
|
516 | this.dispatchConfig = dispatchConfig;
|
517 | this._targetInst = targetInst;
|
518 | this.nativeEvent = nativeEvent;
|
519 | var Interface = this.constructor.Interface;
|
520 |
|
521 | for (var propName in Interface) {
|
522 | if (!Interface.hasOwnProperty(propName)) {
|
523 | continue;
|
524 | }
|
525 |
|
526 | {
|
527 | delete this[propName];
|
528 | }
|
529 |
|
530 | var normalize = Interface[propName];
|
531 |
|
532 | if (normalize) {
|
533 | this[propName] = normalize(nativeEvent);
|
534 | } else {
|
535 | if (propName === 'target') {
|
536 | this.target = nativeEventTarget;
|
537 | } else {
|
538 | this[propName] = nativeEvent[propName];
|
539 | }
|
540 | }
|
541 | }
|
542 |
|
543 | var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false;
|
544 |
|
545 | if (defaultPrevented) {
|
546 | this.isDefaultPrevented = functionThatReturnsTrue;
|
547 | } else {
|
548 | this.isDefaultPrevented = functionThatReturnsFalse;
|
549 | }
|
550 |
|
551 | this.isPropagationStopped = functionThatReturnsFalse;
|
552 | return this;
|
553 | }
|
554 |
|
555 | _assign(SyntheticEvent.prototype, {
|
556 | preventDefault: function () {
|
557 | this.defaultPrevented = true;
|
558 | var event = this.nativeEvent;
|
559 |
|
560 | if (!event) {
|
561 | return;
|
562 | }
|
563 |
|
564 | if (event.preventDefault) {
|
565 | event.preventDefault();
|
566 | } else if (typeof event.returnValue !== 'unknown') {
|
567 | event.returnValue = false;
|
568 | }
|
569 |
|
570 | this.isDefaultPrevented = functionThatReturnsTrue;
|
571 | },
|
572 | stopPropagation: function () {
|
573 | var event = this.nativeEvent;
|
574 |
|
575 | if (!event) {
|
576 | return;
|
577 | }
|
578 |
|
579 | if (event.stopPropagation) {
|
580 | event.stopPropagation();
|
581 | } else if (typeof event.cancelBubble !== 'unknown') {
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 | event.cancelBubble = true;
|
588 | }
|
589 |
|
590 | this.isPropagationStopped = functionThatReturnsTrue;
|
591 | },
|
592 |
|
593 | |
594 |
|
595 |
|
596 |
|
597 |
|
598 | persist: function () {
|
599 | this.isPersistent = functionThatReturnsTrue;
|
600 | },
|
601 |
|
602 | |
603 |
|
604 |
|
605 |
|
606 |
|
607 | isPersistent: functionThatReturnsFalse,
|
608 |
|
609 | |
610 |
|
611 |
|
612 | destructor: function () {
|
613 | var Interface = this.constructor.Interface;
|
614 |
|
615 | for (var propName in Interface) {
|
616 | {
|
617 | Object.defineProperty(this, propName, getPooledWarningPropertyDefinition(propName, Interface[propName]));
|
618 | }
|
619 | }
|
620 |
|
621 | this.dispatchConfig = null;
|
622 | this._targetInst = null;
|
623 | this.nativeEvent = null;
|
624 | this.isDefaultPrevented = functionThatReturnsFalse;
|
625 | this.isPropagationStopped = functionThatReturnsFalse;
|
626 | this._dispatchListeners = null;
|
627 | this._dispatchInstances = null;
|
628 |
|
629 | {
|
630 | Object.defineProperty(this, 'nativeEvent', getPooledWarningPropertyDefinition('nativeEvent', null));
|
631 | Object.defineProperty(this, 'isDefaultPrevented', getPooledWarningPropertyDefinition('isDefaultPrevented', functionThatReturnsFalse));
|
632 | Object.defineProperty(this, 'isPropagationStopped', getPooledWarningPropertyDefinition('isPropagationStopped', functionThatReturnsFalse));
|
633 | Object.defineProperty(this, 'preventDefault', getPooledWarningPropertyDefinition('preventDefault', function () {}));
|
634 | Object.defineProperty(this, 'stopPropagation', getPooledWarningPropertyDefinition('stopPropagation', function () {}));
|
635 | }
|
636 | }
|
637 | });
|
638 |
|
639 | SyntheticEvent.Interface = EventInterface;
|
640 |
|
641 |
|
642 |
|
643 |
|
644 | SyntheticEvent.extend = function (Interface) {
|
645 | var Super = this;
|
646 |
|
647 | var E = function () {};
|
648 |
|
649 | E.prototype = Super.prototype;
|
650 | var prototype = new E();
|
651 |
|
652 | function Class() {
|
653 | return Super.apply(this, arguments);
|
654 | }
|
655 |
|
656 | _assign(prototype, Class.prototype);
|
657 |
|
658 | Class.prototype = prototype;
|
659 | Class.prototype.constructor = Class;
|
660 | Class.Interface = _assign({}, Super.Interface, Interface);
|
661 | Class.extend = Super.extend;
|
662 | addEventPoolingTo(Class);
|
663 | return Class;
|
664 | };
|
665 |
|
666 | addEventPoolingTo(SyntheticEvent);
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 | function getPooledWarningPropertyDefinition(propName, getVal) {
|
676 | var isFunction = typeof getVal === 'function';
|
677 | return {
|
678 | configurable: true,
|
679 | set: set,
|
680 | get: get
|
681 | };
|
682 |
|
683 | function set(val) {
|
684 | var action = isFunction ? 'setting the method' : 'setting the property';
|
685 | warn(action, 'This is effectively a no-op');
|
686 | return val;
|
687 | }
|
688 |
|
689 | function get() {
|
690 | var action = isFunction ? 'accessing the method' : 'accessing the property';
|
691 | var result = isFunction ? 'This is a no-op function' : 'This is set to null';
|
692 | warn(action, result);
|
693 | return getVal;
|
694 | }
|
695 |
|
696 | function warn(action, result) {
|
697 | var warningCondition = false;
|
698 | !warningCondition ? warningWithoutStack$1(false, "This synthetic event is reused for performance reasons. If you're seeing this, " + "you're %s `%s` on a released/nullified synthetic event. %s. " + 'If you must keep the original synthetic event around, use event.persist(). ' + 'See https://fb.me/react-event-pooling for more information.', action, propName, result) : void 0;
|
699 | }
|
700 | }
|
701 |
|
702 | function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) {
|
703 | var EventConstructor = this;
|
704 |
|
705 | if (EventConstructor.eventPool.length) {
|
706 | var instance = EventConstructor.eventPool.pop();
|
707 | EventConstructor.call(instance, dispatchConfig, targetInst, nativeEvent, nativeInst);
|
708 | return instance;
|
709 | }
|
710 |
|
711 | return new EventConstructor(dispatchConfig, targetInst, nativeEvent, nativeInst);
|
712 | }
|
713 |
|
714 | function releasePooledEvent(event) {
|
715 | var EventConstructor = this;
|
716 |
|
717 | if (!(event instanceof EventConstructor)) {
|
718 | {
|
719 | throw Error("Trying to release an event instance into a pool of a different type.");
|
720 | }
|
721 | }
|
722 |
|
723 | event.destructor();
|
724 |
|
725 | if (EventConstructor.eventPool.length < EVENT_POOL_SIZE) {
|
726 | EventConstructor.eventPool.push(event);
|
727 | }
|
728 | }
|
729 |
|
730 | function addEventPoolingTo(EventConstructor) {
|
731 | EventConstructor.eventPool = [];
|
732 | EventConstructor.getPooled = getPooledEvent;
|
733 | EventConstructor.release = releasePooledEvent;
|
734 | }
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 | var lowPriorityWarningWithoutStack = function () {};
|
750 |
|
751 | {
|
752 | var printWarning = function (format) {
|
753 | for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
754 | args[_key - 1] = arguments[_key];
|
755 | }
|
756 |
|
757 | var argIndex = 0;
|
758 | var message = 'Warning: ' + format.replace(/%s/g, function () {
|
759 | return args[argIndex++];
|
760 | });
|
761 |
|
762 | if (typeof console !== 'undefined') {
|
763 | console.warn(message);
|
764 | }
|
765 |
|
766 | try {
|
767 |
|
768 |
|
769 |
|
770 | throw new Error(message);
|
771 | } catch (x) {}
|
772 | };
|
773 |
|
774 | lowPriorityWarningWithoutStack = function (condition, format) {
|
775 | if (format === undefined) {
|
776 | throw new Error('`lowPriorityWarningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
|
777 | }
|
778 |
|
779 | if (!condition) {
|
780 | for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
781 | args[_key2 - 2] = arguments[_key2];
|
782 | }
|
783 |
|
784 | printWarning.apply(void 0, [format].concat(args));
|
785 | }
|
786 | };
|
787 | }
|
788 |
|
789 | var lowPriorityWarningWithoutStack$1 = lowPriorityWarningWithoutStack;
|
790 |
|
791 |
|
792 |
|
793 |
|
794 | var ELEMENT_NODE = 1;
|
795 |
|
796 |
|
797 |
|
798 |
|
799 | function unsafeCastStringToDOMTopLevelType(topLevelType) {
|
800 | return topLevelType;
|
801 | }
|
802 |
|
803 | var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 | function makePrefixMap(styleProp, eventName) {
|
814 | var prefixes = {};
|
815 | prefixes[styleProp.toLowerCase()] = eventName.toLowerCase();
|
816 | prefixes['Webkit' + styleProp] = 'webkit' + eventName;
|
817 | prefixes['Moz' + styleProp] = 'moz' + eventName;
|
818 | return prefixes;
|
819 | }
|
820 |
|
821 |
|
822 |
|
823 |
|
824 |
|
825 | var vendorPrefixes = {
|
826 | animationend: makePrefixMap('Animation', 'AnimationEnd'),
|
827 | animationiteration: makePrefixMap('Animation', 'AnimationIteration'),
|
828 | animationstart: makePrefixMap('Animation', 'AnimationStart'),
|
829 | transitionend: makePrefixMap('Transition', 'TransitionEnd')
|
830 | };
|
831 |
|
832 |
|
833 |
|
834 |
|
835 | var prefixedEventNames = {};
|
836 |
|
837 |
|
838 |
|
839 |
|
840 | var style = {};
|
841 |
|
842 |
|
843 |
|
844 |
|
845 | if (canUseDOM) {
|
846 | style = document.createElement('div').style;
|
847 |
|
848 |
|
849 |
|
850 |
|
851 | if (!('AnimationEvent' in window)) {
|
852 | delete vendorPrefixes.animationend.animation;
|
853 | delete vendorPrefixes.animationiteration.animation;
|
854 | delete vendorPrefixes.animationstart.animation;
|
855 | }
|
856 |
|
857 |
|
858 | if (!('TransitionEvent' in window)) {
|
859 | delete vendorPrefixes.transitionend.transition;
|
860 | }
|
861 | }
|
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 |
|
869 |
|
870 | function getVendorPrefixedEventName(eventName) {
|
871 | if (prefixedEventNames[eventName]) {
|
872 | return prefixedEventNames[eventName];
|
873 | } else if (!vendorPrefixes[eventName]) {
|
874 | return eventName;
|
875 | }
|
876 |
|
877 | var prefixMap = vendorPrefixes[eventName];
|
878 |
|
879 | for (var styleProp in prefixMap) {
|
880 | if (prefixMap.hasOwnProperty(styleProp) && styleProp in style) {
|
881 | return prefixedEventNames[eventName] = prefixMap[styleProp];
|
882 | }
|
883 | }
|
884 |
|
885 | return eventName;
|
886 | }
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 | var TOP_ABORT = unsafeCastStringToDOMTopLevelType('abort');
|
897 | var TOP_ANIMATION_END = unsafeCastStringToDOMTopLevelType(getVendorPrefixedEventName('animationend'));
|
898 | var TOP_ANIMATION_ITERATION = unsafeCastStringToDOMTopLevelType(getVendorPrefixedEventName('animationiteration'));
|
899 | var TOP_ANIMATION_START = unsafeCastStringToDOMTopLevelType(getVendorPrefixedEventName('animationstart'));
|
900 | var TOP_BLUR = unsafeCastStringToDOMTopLevelType('blur');
|
901 | var TOP_CAN_PLAY = unsafeCastStringToDOMTopLevelType('canplay');
|
902 | var TOP_CAN_PLAY_THROUGH = unsafeCastStringToDOMTopLevelType('canplaythrough');
|
903 | var TOP_CANCEL = unsafeCastStringToDOMTopLevelType('cancel');
|
904 | var TOP_CHANGE = unsafeCastStringToDOMTopLevelType('change');
|
905 | var TOP_CLICK = unsafeCastStringToDOMTopLevelType('click');
|
906 | var TOP_CLOSE = unsafeCastStringToDOMTopLevelType('close');
|
907 | var TOP_COMPOSITION_END = unsafeCastStringToDOMTopLevelType('compositionend');
|
908 | var TOP_COMPOSITION_START = unsafeCastStringToDOMTopLevelType('compositionstart');
|
909 | var TOP_COMPOSITION_UPDATE = unsafeCastStringToDOMTopLevelType('compositionupdate');
|
910 | var TOP_CONTEXT_MENU = unsafeCastStringToDOMTopLevelType('contextmenu');
|
911 | var TOP_COPY = unsafeCastStringToDOMTopLevelType('copy');
|
912 | var TOP_CUT = unsafeCastStringToDOMTopLevelType('cut');
|
913 | var TOP_DOUBLE_CLICK = unsafeCastStringToDOMTopLevelType('dblclick');
|
914 |
|
915 | var TOP_DRAG = unsafeCastStringToDOMTopLevelType('drag');
|
916 | var TOP_DRAG_END = unsafeCastStringToDOMTopLevelType('dragend');
|
917 | var TOP_DRAG_ENTER = unsafeCastStringToDOMTopLevelType('dragenter');
|
918 | var TOP_DRAG_EXIT = unsafeCastStringToDOMTopLevelType('dragexit');
|
919 | var TOP_DRAG_LEAVE = unsafeCastStringToDOMTopLevelType('dragleave');
|
920 | var TOP_DRAG_OVER = unsafeCastStringToDOMTopLevelType('dragover');
|
921 | var TOP_DRAG_START = unsafeCastStringToDOMTopLevelType('dragstart');
|
922 | var TOP_DROP = unsafeCastStringToDOMTopLevelType('drop');
|
923 | var TOP_DURATION_CHANGE = unsafeCastStringToDOMTopLevelType('durationchange');
|
924 | var TOP_EMPTIED = unsafeCastStringToDOMTopLevelType('emptied');
|
925 | var TOP_ENCRYPTED = unsafeCastStringToDOMTopLevelType('encrypted');
|
926 | var TOP_ENDED = unsafeCastStringToDOMTopLevelType('ended');
|
927 | var TOP_ERROR = unsafeCastStringToDOMTopLevelType('error');
|
928 | var TOP_FOCUS = unsafeCastStringToDOMTopLevelType('focus');
|
929 |
|
930 | var TOP_INPUT = unsafeCastStringToDOMTopLevelType('input');
|
931 |
|
932 | var TOP_KEY_DOWN = unsafeCastStringToDOMTopLevelType('keydown');
|
933 | var TOP_KEY_PRESS = unsafeCastStringToDOMTopLevelType('keypress');
|
934 | var TOP_KEY_UP = unsafeCastStringToDOMTopLevelType('keyup');
|
935 | var TOP_LOAD = unsafeCastStringToDOMTopLevelType('load');
|
936 | var TOP_LOAD_START = unsafeCastStringToDOMTopLevelType('loadstart');
|
937 | var TOP_LOADED_DATA = unsafeCastStringToDOMTopLevelType('loadeddata');
|
938 | var TOP_LOADED_METADATA = unsafeCastStringToDOMTopLevelType('loadedmetadata');
|
939 |
|
940 | var TOP_MOUSE_DOWN = unsafeCastStringToDOMTopLevelType('mousedown');
|
941 | var TOP_MOUSE_MOVE = unsafeCastStringToDOMTopLevelType('mousemove');
|
942 | var TOP_MOUSE_OUT = unsafeCastStringToDOMTopLevelType('mouseout');
|
943 | var TOP_MOUSE_OVER = unsafeCastStringToDOMTopLevelType('mouseover');
|
944 | var TOP_MOUSE_UP = unsafeCastStringToDOMTopLevelType('mouseup');
|
945 | var TOP_PASTE = unsafeCastStringToDOMTopLevelType('paste');
|
946 | var TOP_PAUSE = unsafeCastStringToDOMTopLevelType('pause');
|
947 | var TOP_PLAY = unsafeCastStringToDOMTopLevelType('play');
|
948 | var TOP_PLAYING = unsafeCastStringToDOMTopLevelType('playing');
|
949 |
|
950 |
|
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 | var TOP_PROGRESS = unsafeCastStringToDOMTopLevelType('progress');
|
958 | var TOP_RATE_CHANGE = unsafeCastStringToDOMTopLevelType('ratechange');
|
959 |
|
960 | var TOP_SCROLL = unsafeCastStringToDOMTopLevelType('scroll');
|
961 | var TOP_SEEKED = unsafeCastStringToDOMTopLevelType('seeked');
|
962 | var TOP_SEEKING = unsafeCastStringToDOMTopLevelType('seeking');
|
963 | var TOP_SELECTION_CHANGE = unsafeCastStringToDOMTopLevelType('selectionchange');
|
964 | var TOP_STALLED = unsafeCastStringToDOMTopLevelType('stalled');
|
965 |
|
966 | var TOP_SUSPEND = unsafeCastStringToDOMTopLevelType('suspend');
|
967 | var TOP_TEXT_INPUT = unsafeCastStringToDOMTopLevelType('textInput');
|
968 | var TOP_TIME_UPDATE = unsafeCastStringToDOMTopLevelType('timeupdate');
|
969 | var TOP_TOGGLE = unsafeCastStringToDOMTopLevelType('toggle');
|
970 | var TOP_TOUCH_CANCEL = unsafeCastStringToDOMTopLevelType('touchcancel');
|
971 | var TOP_TOUCH_END = unsafeCastStringToDOMTopLevelType('touchend');
|
972 | var TOP_TOUCH_MOVE = unsafeCastStringToDOMTopLevelType('touchmove');
|
973 | var TOP_TOUCH_START = unsafeCastStringToDOMTopLevelType('touchstart');
|
974 | var TOP_TRANSITION_END = unsafeCastStringToDOMTopLevelType(getVendorPrefixedEventName('transitionend'));
|
975 | var TOP_VOLUME_CHANGE = unsafeCastStringToDOMTopLevelType('volumechange');
|
976 | var TOP_WAITING = unsafeCastStringToDOMTopLevelType('waiting');
|
977 | var TOP_WHEEL = unsafeCastStringToDOMTopLevelType('wheel');
|
978 |
|
979 |
|
980 |
|
981 | var PLUGIN_EVENT_SYSTEM = 1;
|
982 |
|
983 | var didWarnAboutMessageChannel = false;
|
984 | var enqueueTask;
|
985 |
|
986 | try {
|
987 |
|
988 |
|
989 | var requireString = ('require' + Math.random()).slice(0, 7);
|
990 | var nodeRequire = module && module[requireString];
|
991 |
|
992 |
|
993 | enqueueTask = nodeRequire('timers').setImmediate;
|
994 | } catch (_err) {
|
995 |
|
996 |
|
997 |
|
998 | enqueueTask = function (callback) {
|
999 | {
|
1000 | if (didWarnAboutMessageChannel === false) {
|
1001 | didWarnAboutMessageChannel = true;
|
1002 | !(typeof MessageChannel !== 'undefined') ? warningWithoutStack$1(false, 'This browser does not have a MessageChannel implementation, ' + 'so enqueuing tasks via await act(async () => ...) will fail. ' + 'Please file an issue at https://github.com/facebook/react/issues ' + 'if you encounter this warning.') : void 0;
|
1003 | }
|
1004 | }
|
1005 |
|
1006 | var channel = new MessageChannel();
|
1007 | channel.port1.onmessage = callback;
|
1008 | channel.port2.postMessage(undefined);
|
1009 | };
|
1010 | }
|
1011 |
|
1012 | var enqueueTask$1 = enqueueTask;
|
1013 |
|
1014 | var ReactInternals$1 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
1015 | var _ReactInternals$Sched = ReactInternals$1.Scheduler;
|
1016 | var unstable_cancelCallback = _ReactInternals$Sched.unstable_cancelCallback;
|
1017 | var unstable_now = _ReactInternals$Sched.unstable_now;
|
1018 | var unstable_scheduleCallback = _ReactInternals$Sched.unstable_scheduleCallback;
|
1019 | var unstable_shouldYield = _ReactInternals$Sched.unstable_shouldYield;
|
1020 | var unstable_requestPaint = _ReactInternals$Sched.unstable_requestPaint;
|
1021 | var unstable_getFirstCallbackNode = _ReactInternals$Sched.unstable_getFirstCallbackNode;
|
1022 | var unstable_runWithPriority = _ReactInternals$Sched.unstable_runWithPriority;
|
1023 | var unstable_next = _ReactInternals$Sched.unstable_next;
|
1024 | var unstable_continueExecution = _ReactInternals$Sched.unstable_continueExecution;
|
1025 | var unstable_pauseExecution = _ReactInternals$Sched.unstable_pauseExecution;
|
1026 | var unstable_getCurrentPriorityLevel = _ReactInternals$Sched.unstable_getCurrentPriorityLevel;
|
1027 | var unstable_ImmediatePriority = _ReactInternals$Sched.unstable_ImmediatePriority;
|
1028 | var unstable_UserBlockingPriority = _ReactInternals$Sched.unstable_UserBlockingPriority;
|
1029 | var unstable_NormalPriority = _ReactInternals$Sched.unstable_NormalPriority;
|
1030 | var unstable_LowPriority = _ReactInternals$Sched.unstable_LowPriority;
|
1031 | var unstable_IdlePriority = _ReactInternals$Sched.unstable_IdlePriority;
|
1032 | var unstable_forceFrameRate = _ReactInternals$Sched.unstable_forceFrameRate;
|
1033 | var unstable_flushAllWithoutAsserting = _ReactInternals$Sched.unstable_flushAllWithoutAsserting;
|
1034 |
|
1035 | // ReactDOM.js, and ReactTestUtils.js:
|
1036 |
|
1037 | var _ReactDOM$__SECRET_IN$1 = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events;
|
1038 | var getInstanceFromNode$1 = _ReactDOM$__SECRET_IN$1[0];
|
1039 | var getNodeFromInstance$1 = _ReactDOM$__SECRET_IN$1[1];
|
1040 | var getFiberCurrentPropsFromNode$1 = _ReactDOM$__SECRET_IN$1[2];
|
1041 | var injectEventPluginsByName$1 = _ReactDOM$__SECRET_IN$1[3];
|
1042 | var eventNameDispatchConfigs$1 = _ReactDOM$__SECRET_IN$1[4];
|
1043 | var accumulateTwoPhaseDispatches$1 = _ReactDOM$__SECRET_IN$1[5];
|
1044 | var accumulateDirectDispatches$1 = _ReactDOM$__SECRET_IN$1[6];
|
1045 | var enqueueStateRestore$1 = _ReactDOM$__SECRET_IN$1[7];
|
1046 | var restoreStateIfNeeded$1 = _ReactDOM$__SECRET_IN$1[8];
|
1047 | var dispatchEvent$1 = _ReactDOM$__SECRET_IN$1[9];
|
1048 | var runEventsInBatch$1 = _ReactDOM$__SECRET_IN$1[10];
|
1049 | var flushPassiveEffects$1 = _ReactDOM$__SECRET_IN$1[11];
|
1050 | var IsThisRendererActing$1 = _ReactDOM$__SECRET_IN$1[12];
|
1051 | var batchedUpdates = ReactDOM.unstable_batchedUpdates;
|
1052 | var IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing; // this implementation should be exactly the same in
|
1053 | // ReactTestUtilsAct.js, ReactTestRendererAct.js, createReactNoop.js
|
1054 |
|
1055 | var isSchedulerMocked = typeof unstable_flushAllWithoutAsserting === 'function';
|
1056 |
|
1057 | var flushWork = unstable_flushAllWithoutAsserting || function () {
|
1058 | var didFlushWork = false;
|
1059 |
|
1060 | while (flushPassiveEffects$1()) {
|
1061 | didFlushWork = true;
|
1062 | }
|
1063 |
|
1064 | return didFlushWork;
|
1065 | };
|
1066 |
|
1067 | function flushWorkAndMicroTasks(onDone) {
|
1068 | try {
|
1069 | flushWork();
|
1070 | enqueueTask$1(function () {
|
1071 | if (flushWork()) {
|
1072 | flushWorkAndMicroTasks(onDone);
|
1073 | } else {
|
1074 | onDone();
|
1075 | }
|
1076 | });
|
1077 | } catch (err) {
|
1078 | onDone(err);
|
1079 | }
|
1080 | } // we track the 'depth' of the act() calls with this counter,
|
1081 | // so we can tell if any async act() calls try to run in parallel.
|
1082 |
|
1083 |
|
1084 | var actingUpdatesScopeDepth = 0;
|
1085 | function act(callback) {
|
1086 | var previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
|
1087 | var previousIsSomeRendererActing;
|
1088 | var previousIsThisRendererActing;
|
1089 | actingUpdatesScopeDepth++;
|
1090 | previousIsSomeRendererActing = IsSomeRendererActing.current;
|
1091 | previousIsThisRendererActing = IsThisRendererActing$1.current;
|
1092 | IsSomeRendererActing.current = true;
|
1093 | IsThisRendererActing$1.current = true;
|
1094 |
|
1095 | function onDone() {
|
1096 | actingUpdatesScopeDepth--;
|
1097 | IsSomeRendererActing.current = previousIsSomeRendererActing;
|
1098 | IsThisRendererActing$1.current = previousIsThisRendererActing;
|
1099 |
|
1100 | {
|
1101 | if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) {
|
1102 | // if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned
|
1103 | warningWithoutStack$1(false, 'You seem to have overlapping act() calls, this is not supported. ' + 'Be sure to await previous act() calls before making a new one. ');
|
1104 | }
|
1105 | }
|
1106 | }
|
1107 |
|
1108 | var result;
|
1109 |
|
1110 | try {
|
1111 | result = batchedUpdates(callback);
|
1112 | } catch (error) {
|
1113 | // on sync errors, we still want to 'cleanup' and decrement actingUpdatesScopeDepth
|
1114 | onDone();
|
1115 | throw error;
|
1116 | }
|
1117 |
|
1118 | if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
|
1119 | // setup a boolean that gets set to true only
|
1120 | // once this act() call is await-ed
|
1121 | var called = false;
|
1122 |
|
1123 | {
|
1124 | if (typeof Promise !== 'undefined') {
|
1125 | //eslint-disable-next-line no-undef
|
1126 | Promise.resolve().then(function () {}).then(function () {
|
1127 | if (called === false) {
|
1128 | warningWithoutStack$1(false, 'You called act(async () => ...) without await. ' + 'This could lead to unexpected testing behaviour, interleaving multiple act ' + 'calls and mixing their scopes. You should - await act(async () => ...);');
|
1129 | }
|
1130 | });
|
1131 | }
|
1132 | } // in the async case, the returned thenable runs the callback, flushes
|
1133 | // effects and microtasks in a loop until flushPassiveEffects() === false,
|
1134 | // and cleans up
|
1135 |
|
1136 |
|
1137 | return {
|
1138 | then: function (resolve, reject) {
|
1139 | called = true;
|
1140 | result.then(function () {
|
1141 | if (actingUpdatesScopeDepth > 1 || isSchedulerMocked === true && previousIsSomeRendererActing === true) {
|
1142 | onDone();
|
1143 | resolve();
|
1144 | return;
|
1145 | } // we're about to exit the act() scope,
|
1146 | // now's the time to flush tasks/effects
|
1147 |
|
1148 |
|
1149 | flushWorkAndMicroTasks(function (err) {
|
1150 | onDone();
|
1151 |
|
1152 | if (err) {
|
1153 | reject(err);
|
1154 | } else {
|
1155 | resolve();
|
1156 | }
|
1157 | });
|
1158 | }, function (err) {
|
1159 | onDone();
|
1160 | reject(err);
|
1161 | });
|
1162 | }
|
1163 | };
|
1164 | } else {
|
1165 | {
|
1166 | !(result === undefined) ? warningWithoutStack$1(false, 'The callback passed to act(...) function ' + 'must return undefined, or a Promise. You returned %s', result) : void 0;
|
1167 | } // flush effects until none remain, and cleanup
|
1168 |
|
1169 |
|
1170 | try {
|
1171 | if (actingUpdatesScopeDepth === 1 && (isSchedulerMocked === false || previousIsSomeRendererActing === false)) {
|
1172 | // we're about to exit the act() scope,
|
1173 | // now's the time to flush effects
|
1174 | flushWork();
|
1175 | }
|
1176 |
|
1177 | onDone();
|
1178 | } catch (err) {
|
1179 | onDone();
|
1180 | throw err;
|
1181 | } // in the sync case, the returned thenable only warns *if* await-ed
|
1182 |
|
1183 |
|
1184 | return {
|
1185 | then: function (resolve) {
|
1186 | {
|
1187 | warningWithoutStack$1(false, 'Do not await the result of calling act(...) with sync logic, it is not a Promise.');
|
1188 | }
|
1189 |
|
1190 | resolve();
|
1191 | }
|
1192 | };
|
1193 | }
|
1194 | }
|
1195 |
|
1196 | var findDOMNode = ReactDOM.findDOMNode; // Keep in sync with ReactDOMUnstableNativeDependencies.js
|
1197 | // ReactDOM.js, and ReactTestUtilsAct.js:
|
1198 |
|
1199 | var _ReactDOM$__SECRET_IN = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events;
|
1200 | var getInstanceFromNode = _ReactDOM$__SECRET_IN[0];
|
1201 | var getNodeFromInstance = _ReactDOM$__SECRET_IN[1];
|
1202 | var getFiberCurrentPropsFromNode = _ReactDOM$__SECRET_IN[2];
|
1203 | var injectEventPluginsByName = _ReactDOM$__SECRET_IN[3];
|
1204 | var eventNameDispatchConfigs = _ReactDOM$__SECRET_IN[4];
|
1205 | var accumulateTwoPhaseDispatches = _ReactDOM$__SECRET_IN[5];
|
1206 | var accumulateDirectDispatches = _ReactDOM$__SECRET_IN[6];
|
1207 | var enqueueStateRestore = _ReactDOM$__SECRET_IN[7];
|
1208 | var restoreStateIfNeeded = _ReactDOM$__SECRET_IN[8];
|
1209 | var dispatchEvent = _ReactDOM$__SECRET_IN[9];
|
1210 | var runEventsInBatch = _ReactDOM$__SECRET_IN[10];
|
1211 | var flushPassiveEffects = _ReactDOM$__SECRET_IN[11];
|
1212 | var IsThisRendererActing = _ReactDOM$__SECRET_IN[12];
|
1213 |
|
1214 | function Event(suffix) {}
|
1215 |
|
1216 | var hasWarnedAboutDeprecatedMockComponent = false;
|
1217 | /**
|
1218 | * @class ReactTestUtils
|
1219 | */
|
1220 |
|
1221 | /**
|
1222 | * Simulates a top level event being dispatched from a raw event that occurred
|
1223 | * on an `Element` node.
|
1224 | * @param {number} topLevelType A number from `TopLevelEventTypes`
|
1225 | * @param {!Element} node The dom to simulate an event occurring on.
|
1226 | * @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
|
1227 | */
|
1228 |
|
1229 | function simulateNativeEventOnNode(topLevelType, node, fakeNativeEvent) {
|
1230 | fakeNativeEvent.target = node;
|
1231 | dispatchEvent(topLevelType, PLUGIN_EVENT_SYSTEM, fakeNativeEvent);
|
1232 | }
|
1233 | /**
|
1234 | * Simulates a top level event being dispatched from a raw event that occurred
|
1235 | * on the `ReactDOMComponent` `comp`.
|
1236 | * @param {Object} topLevelType A type from `BrowserEventConstants.topLevelTypes`.
|
1237 | * @param {!ReactDOMComponent} comp
|
1238 | * @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
|
1239 | */
|
1240 |
|
1241 |
|
1242 | function simulateNativeEventOnDOMComponent(topLevelType, comp, fakeNativeEvent) {
|
1243 | simulateNativeEventOnNode(topLevelType, findDOMNode(comp), fakeNativeEvent);
|
1244 | }
|
1245 |
|
1246 | function findAllInRenderedFiberTreeInternal(fiber, test) {
|
1247 | if (!fiber) {
|
1248 | return [];
|
1249 | }
|
1250 |
|
1251 | var currentParent = findCurrentFiberUsingSlowPath(fiber);
|
1252 |
|
1253 | if (!currentParent) {
|
1254 | return [];
|
1255 | }
|
1256 |
|
1257 | var node = currentParent;
|
1258 | var ret = [];
|
1259 |
|
1260 | while (true) {
|
1261 | if (node.tag === HostComponent || node.tag === HostText || node.tag === ClassComponent || node.tag === FunctionComponent) {
|
1262 | var publicInst = node.stateNode;
|
1263 |
|
1264 | if (test(publicInst)) {
|
1265 | ret.push(publicInst);
|
1266 | }
|
1267 | }
|
1268 |
|
1269 | if (node.child) {
|
1270 | node.child.return = node;
|
1271 | node = node.child;
|
1272 | continue;
|
1273 | }
|
1274 |
|
1275 | if (node === currentParent) {
|
1276 | return ret;
|
1277 | }
|
1278 |
|
1279 | while (!node.sibling) {
|
1280 | if (!node.return || node.return === currentParent) {
|
1281 | return ret;
|
1282 | }
|
1283 |
|
1284 | node = node.return;
|
1285 | }
|
1286 |
|
1287 | node.sibling.return = node.return;
|
1288 | node = node.sibling;
|
1289 | }
|
1290 | }
|
1291 |
|
1292 | function validateClassInstance(inst, methodName) {
|
1293 | if (!inst) {
|
1294 | // This is probably too relaxed but it's existing behavior.
|
1295 | return;
|
1296 | }
|
1297 |
|
1298 | if (get(inst)) {
|
1299 | // This is a public instance indeed.
|
1300 | return;
|
1301 | }
|
1302 |
|
1303 | var received;
|
1304 | var stringified = '' + inst;
|
1305 |
|
1306 | if (Array.isArray(inst)) {
|
1307 | received = 'an array';
|
1308 | } else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
|
1309 | received = 'a DOM node';
|
1310 | } else if (stringified === '[object Object]') {
|
1311 | received = 'object with keys {' + Object.keys(inst).join(', ') + '}';
|
1312 | } else {
|
1313 | received = stringified;
|
1314 | }
|
1315 |
|
1316 | {
|
1317 | {
|
1318 | throw Error(methodName + "(...): the first argument must be a React class instance. Instead received: " + received + ".");
|
1319 | }
|
1320 | }
|
1321 | }
|
1322 | /**
|
1323 | * Utilities for making it easy to test React components.
|
1324 | *
|
1325 | * See https://reactjs.org/docs/test-utils.html
|
1326 | *
|
1327 | * Todo: Support the entire DOM.scry query syntax. For now, these simple
|
1328 | * utilities will suffice for testing purposes.
|
1329 | * @lends ReactTestUtils
|
1330 | */
|
1331 |
|
1332 |
|
1333 | var ReactTestUtils = {
|
1334 | renderIntoDocument: function (element) {
|
1335 | var div = document.createElement('div'); // None of our tests actually require attaching the container to the
|
1336 | // DOM, and doing so creates a mess that we rely on test isolation to
|
1337 | // clean up, so we're going to stop honoring the name of this method
|
1338 | // (and probably rename it eventually) if no problems arise.
|
1339 | // document.documentElement.appendChild(div);
|
1340 |
|
1341 | return ReactDOM.render(element, div);
|
1342 | },
|
1343 | isElement: function (element) {
|
1344 | return React.isValidElement(element);
|
1345 | },
|
1346 | isElementOfType: function (inst, convenienceConstructor) {
|
1347 | return React.isValidElement(inst) && inst.type === convenienceConstructor;
|
1348 | },
|
1349 | isDOMComponent: function (inst) {
|
1350 | return !!(inst && inst.nodeType === ELEMENT_NODE && inst.tagName);
|
1351 | },
|
1352 | isDOMComponentElement: function (inst) {
|
1353 | return !!(inst && React.isValidElement(inst) && !!inst.tagName);
|
1354 | },
|
1355 | isCompositeComponent: function (inst) {
|
1356 | if (ReactTestUtils.isDOMComponent(inst)) {
|
1357 | // Accessing inst.setState warns; just return false as that'll be what
|
1358 | // this returns when we have DOM nodes as refs directly
|
1359 | return false;
|
1360 | }
|
1361 |
|
1362 | return inst != null && typeof inst.render === 'function' && typeof inst.setState === 'function';
|
1363 | },
|
1364 | isCompositeComponentWithType: function (inst, type) {
|
1365 | if (!ReactTestUtils.isCompositeComponent(inst)) {
|
1366 | return false;
|
1367 | }
|
1368 |
|
1369 | var internalInstance = get(inst);
|
1370 | var constructor = internalInstance.type;
|
1371 | return constructor === type;
|
1372 | },
|
1373 | findAllInRenderedTree: function (inst, test) {
|
1374 | validateClassInstance(inst, 'findAllInRenderedTree');
|
1375 |
|
1376 | if (!inst) {
|
1377 | return [];
|
1378 | }
|
1379 |
|
1380 | var internalInstance = get(inst);
|
1381 | return findAllInRenderedFiberTreeInternal(internalInstance, test);
|
1382 | },
|
1383 |
|
1384 | /**
|
1385 | * Finds all instance of components in the rendered tree that are DOM
|
1386 | * components with the class name matching `className`.
|
1387 | * @return {array} an array of all the matches.
|
1388 | */
|
1389 | scryRenderedDOMComponentsWithClass: function (root, classNames) {
|
1390 | validateClassInstance(root, 'scryRenderedDOMComponentsWithClass');
|
1391 | return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
1392 | if (ReactTestUtils.isDOMComponent(inst)) {
|
1393 | var className = inst.className;
|
1394 |
|
1395 | if (typeof className !== 'string') {
|
1396 | // SVG, probably.
|
1397 | className = inst.getAttribute('class') || '';
|
1398 | }
|
1399 |
|
1400 | var classList = className.split(/\s+/);
|
1401 |
|
1402 | if (!Array.isArray(classNames)) {
|
1403 | if (!(classNames !== undefined)) {
|
1404 | {
|
1405 | throw Error("TestUtils.scryRenderedDOMComponentsWithClass expects a className as a second argument.");
|
1406 | }
|
1407 | }
|
1408 |
|
1409 | classNames = classNames.split(/\s+/);
|
1410 | }
|
1411 |
|
1412 | return classNames.every(function (name) {
|
1413 | return classList.indexOf(name) !== -1;
|
1414 | });
|
1415 | }
|
1416 |
|
1417 | return false;
|
1418 | });
|
1419 | },
|
1420 |
|
1421 | /**
|
1422 | * Like scryRenderedDOMComponentsWithClass but expects there to be one result,
|
1423 | * and returns that one result, or throws exception if there is any other
|
1424 | * number of matches besides one.
|
1425 | * @return {!ReactDOMComponent} The one match.
|
1426 | */
|
1427 | findRenderedDOMComponentWithClass: function (root, className) {
|
1428 | validateClassInstance(root, 'findRenderedDOMComponentWithClass');
|
1429 | var all = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
|
1430 |
|
1431 | if (all.length !== 1) {
|
1432 | throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for class:' + className);
|
1433 | }
|
1434 |
|
1435 | return all[0];
|
1436 | },
|
1437 |
|
1438 | /**
|
1439 | * Finds all instance of components in the rendered tree that are DOM
|
1440 | * components with the tag name matching `tagName`.
|
1441 | * @return {array} an array of all the matches.
|
1442 | */
|
1443 | scryRenderedDOMComponentsWithTag: function (root, tagName) {
|
1444 | validateClassInstance(root, 'scryRenderedDOMComponentsWithTag');
|
1445 | return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
1446 | return ReactTestUtils.isDOMComponent(inst) && inst.tagName.toUpperCase() === tagName.toUpperCase();
|
1447 | });
|
1448 | },
|
1449 |
|
1450 | /**
|
1451 | * Like scryRenderedDOMComponentsWithTag but expects there to be one result,
|
1452 | * and returns that one result, or throws exception if there is any other
|
1453 | * number of matches besides one.
|
1454 | * @return {!ReactDOMComponent} The one match.
|
1455 | */
|
1456 | findRenderedDOMComponentWithTag: function (root, tagName) {
|
1457 | validateClassInstance(root, 'findRenderedDOMComponentWithTag');
|
1458 | var all = ReactTestUtils.scryRenderedDOMComponentsWithTag(root, tagName);
|
1459 |
|
1460 | if (all.length !== 1) {
|
1461 | throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for tag:' + tagName);
|
1462 | }
|
1463 |
|
1464 | return all[0];
|
1465 | },
|
1466 |
|
1467 | /**
|
1468 | * Finds all instances of components with type equal to `componentType`.
|
1469 | * @return {array} an array of all the matches.
|
1470 | */
|
1471 | scryRenderedComponentsWithType: function (root, componentType) {
|
1472 | validateClassInstance(root, 'scryRenderedComponentsWithType');
|
1473 | return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
1474 | return ReactTestUtils.isCompositeComponentWithType(inst, componentType);
|
1475 | });
|
1476 | },
|
1477 |
|
1478 | /**
|
1479 | * Same as `scryRenderedComponentsWithType` but expects there to be one result
|
1480 | * and returns that one result, or throws exception if there is any other
|
1481 | * number of matches besides one.
|
1482 | * @return {!ReactComponent} The one match.
|
1483 | */
|
1484 | findRenderedComponentWithType: function (root, componentType) {
|
1485 | validateClassInstance(root, 'findRenderedComponentWithType');
|
1486 | var all = ReactTestUtils.scryRenderedComponentsWithType(root, componentType);
|
1487 |
|
1488 | if (all.length !== 1) {
|
1489 | throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for componentType:' + componentType);
|
1490 | }
|
1491 |
|
1492 | return all[0];
|
1493 | },
|
1494 |
|
1495 | /**
|
1496 | * Pass a mocked component module to this method to augment it with
|
1497 | * useful methods that allow it to be used as a dummy React component.
|
1498 | * Instead of rendering as usual, the component will become a simple
|
1499 | * <div> containing any provided children.
|
1500 | *
|
1501 | * @param {object} module the mock function object exported from a
|
1502 | * module that defines the component to be mocked
|
1503 | * @param {?string} mockTagName optional dummy root tag name to return
|
1504 | * from render method (overrides
|
1505 | * module.mockTagName if provided)
|
1506 | * @return {object} the ReactTestUtils object (for chaining)
|
1507 | */
|
1508 | mockComponent: function (module, mockTagName) {
|
1509 | if (!hasWarnedAboutDeprecatedMockComponent) {
|
1510 | hasWarnedAboutDeprecatedMockComponent = true;
|
1511 | lowPriorityWarningWithoutStack$1(false, 'ReactTestUtils.mockComponent() is deprecated. ' + 'Use shallow rendering or jest.mock() instead.\n\n' + 'See https://fb.me/test-utils-mock-component for more information.');
|
1512 | }
|
1513 |
|
1514 | mockTagName = mockTagName || module.mockTagName || 'div';
|
1515 | module.prototype.render.mockImplementation(function () {
|
1516 | return React.createElement(mockTagName, null, this.props.children);
|
1517 | });
|
1518 | return this;
|
1519 | },
|
1520 | nativeTouchData: function (x, y) {
|
1521 | return {
|
1522 | touches: [{
|
1523 | pageX: x,
|
1524 | pageY: y
|
1525 | }]
|
1526 | };
|
1527 | },
|
1528 | Simulate: null,
|
1529 | SimulateNative: {},
|
1530 | act: act
|
1531 | };
|
1532 | /**
|
1533 | * Exports:
|
1534 | *
|
1535 | * - `ReactTestUtils.Simulate.click(Element)`
|
1536 | * - `ReactTestUtils.Simulate.mouseMove(Element)`
|
1537 | * - `ReactTestUtils.Simulate.change(Element)`
|
1538 | * - ... (All keys from event plugin `eventTypes` objects)
|
1539 | */
|
1540 |
|
1541 | function makeSimulator(eventType) {
|
1542 | return function (domNode, eventData) {
|
1543 | if (!!React.isValidElement(domNode)) {
|
1544 | {
|
1545 | throw Error("TestUtils.Simulate expected a DOM node as the first argument but received a React element. Pass the DOM node you wish to simulate the event on instead. Note that TestUtils.Simulate will not work if you are using shallow rendering.");
|
1546 | }
|
1547 | }
|
1548 |
|
1549 | if (!!ReactTestUtils.isCompositeComponent(domNode)) {
|
1550 | {
|
1551 | throw Error("TestUtils.Simulate expected a DOM node as the first argument but received a component instance. Pass the DOM node you wish to simulate the event on instead.");
|
1552 | }
|
1553 | }
|
1554 |
|
1555 | var dispatchConfig = eventNameDispatchConfigs[eventType];
|
1556 | var fakeNativeEvent = new Event();
|
1557 | fakeNativeEvent.target = domNode;
|
1558 | fakeNativeEvent.type = eventType.toLowerCase(); // We don't use SyntheticEvent.getPooled in order to not have to worry about
|
1559 | // properly destroying any properties assigned from `eventData` upon release
|
1560 |
|
1561 | var targetInst = getInstanceFromNode(domNode);
|
1562 | var event = new SyntheticEvent(dispatchConfig, targetInst, fakeNativeEvent, domNode); // Since we aren't using pooling, always persist the event. This will make
|
1563 | // sure it's marked and won't warn when setting additional properties.
|
1564 |
|
1565 | event.persist();
|
1566 |
|
1567 | _assign(event, eventData);
|
1568 |
|
1569 | if (dispatchConfig.phasedRegistrationNames) {
|
1570 | accumulateTwoPhaseDispatches(event);
|
1571 | } else {
|
1572 | accumulateDirectDispatches(event);
|
1573 | }
|
1574 |
|
1575 | ReactDOM.unstable_batchedUpdates(function () {
|
1576 | // Normally extractEvent enqueues a state restore, but we'll just always
|
1577 | // do that since we're by-passing it here.
|
1578 | enqueueStateRestore(domNode);
|
1579 | runEventsInBatch(event);
|
1580 | });
|
1581 | restoreStateIfNeeded();
|
1582 | };
|
1583 | }
|
1584 |
|
1585 | function buildSimulators() {
|
1586 | ReactTestUtils.Simulate = {};
|
1587 | var eventType;
|
1588 |
|
1589 | for (eventType in eventNameDispatchConfigs) {
|
1590 | /**
|
1591 | * @param {!Element|ReactDOMComponent} domComponentOrNode
|
1592 | * @param {?object} eventData Fake event data to use in SyntheticEvent.
|
1593 | */
|
1594 | ReactTestUtils.Simulate[eventType] = makeSimulator(eventType);
|
1595 | }
|
1596 | }
|
1597 |
|
1598 | buildSimulators();
|
1599 | /**
|
1600 | * Exports:
|
1601 | *
|
1602 | * - `ReactTestUtils.SimulateNative.click(Element/ReactDOMComponent)`
|
1603 | * - `ReactTestUtils.SimulateNative.mouseMove(Element/ReactDOMComponent)`
|
1604 | * - `ReactTestUtils.SimulateNative.mouseIn/ReactDOMComponent)`
|
1605 | * - `ReactTestUtils.SimulateNative.mouseOut(Element/ReactDOMComponent)`
|
1606 | * - ... (All keys from `BrowserEventConstants.topLevelTypes`)
|
1607 | *
|
1608 | * Note: Top level event types are a subset of the entire set of handler types
|
1609 | * (which include a broader set of "synthetic" events). For example, onDragDone
|
1610 | * is a synthetic event. Except when testing an event plugin or React's event
|
1611 | * handling code specifically, you probably want to use ReactTestUtils.Simulate
|
1612 | * to dispatch synthetic events.
|
1613 | */
|
1614 |
|
1615 | function makeNativeSimulator(eventType, topLevelType) {
|
1616 | return function (domComponentOrNode, nativeEventData) {
|
1617 | var fakeNativeEvent = new Event(eventType);
|
1618 |
|
1619 | _assign(fakeNativeEvent, nativeEventData);
|
1620 |
|
1621 | if (ReactTestUtils.isDOMComponent(domComponentOrNode)) {
|
1622 | simulateNativeEventOnDOMComponent(topLevelType, domComponentOrNode, fakeNativeEvent);
|
1623 | } else if (domComponentOrNode.tagName) {
|
1624 |
|
1625 | simulateNativeEventOnNode(topLevelType, domComponentOrNode, fakeNativeEvent);
|
1626 | }
|
1627 | };
|
1628 | }
|
1629 |
|
1630 | [[TOP_ABORT, 'abort'], [TOP_ANIMATION_END, 'animationEnd'], [TOP_ANIMATION_ITERATION, 'animationIteration'], [TOP_ANIMATION_START, 'animationStart'], [TOP_BLUR, 'blur'], [TOP_CAN_PLAY_THROUGH, 'canPlayThrough'], [TOP_CAN_PLAY, 'canPlay'], [TOP_CANCEL, 'cancel'], [TOP_CHANGE, 'change'], [TOP_CLICK, 'click'], [TOP_CLOSE, 'close'], [TOP_COMPOSITION_END, 'compositionEnd'], [TOP_COMPOSITION_START, 'compositionStart'], [TOP_COMPOSITION_UPDATE, 'compositionUpdate'], [TOP_CONTEXT_MENU, 'contextMenu'], [TOP_COPY, 'copy'], [TOP_CUT, 'cut'], [TOP_DOUBLE_CLICK, 'doubleClick'], [TOP_DRAG_END, 'dragEnd'], [TOP_DRAG_ENTER, 'dragEnter'], [TOP_DRAG_EXIT, 'dragExit'], [TOP_DRAG_LEAVE, 'dragLeave'], [TOP_DRAG_OVER, 'dragOver'], [TOP_DRAG_START, 'dragStart'], [TOP_DRAG, 'drag'], [TOP_DROP, 'drop'], [TOP_DURATION_CHANGE, 'durationChange'], [TOP_EMPTIED, 'emptied'], [TOP_ENCRYPTED, 'encrypted'], [TOP_ENDED, 'ended'], [TOP_ERROR, 'error'], [TOP_FOCUS, 'focus'], [TOP_INPUT, 'input'], [TOP_KEY_DOWN, 'keyDown'], [TOP_KEY_PRESS, 'keyPress'], [TOP_KEY_UP, 'keyUp'], [TOP_LOAD_START, 'loadStart'], [TOP_LOAD_START, 'loadStart'], [TOP_LOAD, 'load'], [TOP_LOADED_DATA, 'loadedData'], [TOP_LOADED_METADATA, 'loadedMetadata'], [TOP_MOUSE_DOWN, 'mouseDown'], [TOP_MOUSE_MOVE, 'mouseMove'], [TOP_MOUSE_OUT, 'mouseOut'], [TOP_MOUSE_OVER, 'mouseOver'], [TOP_MOUSE_UP, 'mouseUp'], [TOP_PASTE, 'paste'], [TOP_PAUSE, 'pause'], [TOP_PLAY, 'play'], [TOP_PLAYING, 'playing'], [TOP_PROGRESS, 'progress'], [TOP_RATE_CHANGE, 'rateChange'], [TOP_SCROLL, 'scroll'], [TOP_SEEKED, 'seeked'], [TOP_SEEKING, 'seeking'], [TOP_SELECTION_CHANGE, 'selectionChange'], [TOP_STALLED, 'stalled'], [TOP_SUSPEND, 'suspend'], [TOP_TEXT_INPUT, 'textInput'], [TOP_TIME_UPDATE, 'timeUpdate'], [TOP_TOGGLE, 'toggle'], [TOP_TOUCH_CANCEL, 'touchCancel'], [TOP_TOUCH_END, 'touchEnd'], [TOP_TOUCH_MOVE, 'touchMove'], [TOP_TOUCH_START, 'touchStart'], [TOP_TRANSITION_END, 'transitionEnd'], [TOP_VOLUME_CHANGE, 'volumeChange'], [TOP_WAITING, 'waiting'], [TOP_WHEEL, 'wheel']].forEach(function (_ref) {
|
1631 | var topLevelType = _ref[0],
|
1632 | eventType = _ref[1];
|
1633 |
|
1634 | |
1635 |
|
1636 |
|
1637 |
|
1638 | ReactTestUtils.SimulateNative[eventType] = makeNativeSimulator(eventType, topLevelType);
|
1639 | });
|
1640 |
|
1641 |
|
1642 | var ReactTestUtils$2 = Object.freeze({
|
1643 | default: ReactTestUtils
|
1644 | });
|
1645 |
|
1646 | var ReactTestUtils$3 = ( ReactTestUtils$2 && ReactTestUtils ) || ReactTestUtils$2;
|
1647 |
|
1648 |
|
1649 |
|
1650 |
|
1651 |
|
1652 | var testUtils = ReactTestUtils$3.default || ReactTestUtils$3;
|
1653 |
|
1654 | return testUtils;
|
1655 |
|
1656 | })));
|