1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | (function (global, factory) {
|
11 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-dom')) :
|
12 | typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-dom'], factory) :
|
13 | (global = global || self, factory(global.ReactTestUtils = {}, global.React, global.ReactDOM));
|
14 | }(this, (function (exports, React, ReactDOM) { 'use strict';
|
15 |
|
16 | var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function warn(format) {
|
24 | {
|
25 | {
|
26 | for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
27 | args[_key - 1] = arguments[_key];
|
28 | }
|
29 |
|
30 | printWarning('warn', format, args);
|
31 | }
|
32 | }
|
33 | }
|
34 | function error(format) {
|
35 | {
|
36 | {
|
37 | for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
38 | args[_key2 - 1] = arguments[_key2];
|
39 | }
|
40 |
|
41 | printWarning('error', format, args);
|
42 | }
|
43 | }
|
44 | }
|
45 |
|
46 | function printWarning(level, format, args) {
|
47 |
|
48 |
|
49 | {
|
50 | var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
51 | var stack = ReactDebugCurrentFrame.getStackAddendum();
|
52 |
|
53 | if (stack !== '') {
|
54 | format += '%s';
|
55 | args = args.concat([stack]);
|
56 | }
|
57 |
|
58 |
|
59 | var argsWithFormat = args.map(function (item) {
|
60 | return String(item);
|
61 | });
|
62 |
|
63 | argsWithFormat.unshift('Warning: ' + format);
|
64 |
|
65 |
|
66 |
|
67 | Function.prototype.apply.call(console[level], console, argsWithFormat);
|
68 | }
|
69 | }
|
70 |
|
71 | |
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | function get(key) {
|
81 | return key._reactInternals;
|
82 | }
|
83 |
|
84 | var FunctionComponent = 0;
|
85 | var ClassComponent = 1;
|
86 |
|
87 | var HostRoot = 3;
|
88 |
|
89 | var HostComponent = 5;
|
90 | var HostText = 6;
|
91 |
|
92 |
|
93 | var NoFlags =
|
94 |
|
95 | 0;
|
96 |
|
97 | var Placement =
|
98 |
|
99 | 2;
|
100 | var Hydrating =
|
101 |
|
102 | 4096;
|
103 |
|
104 | var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
|
105 | function getNearestMountedFiber(fiber) {
|
106 | var node = fiber;
|
107 | var nearestMounted = fiber;
|
108 |
|
109 | if (!fiber.alternate) {
|
110 |
|
111 |
|
112 | var nextNode = node;
|
113 |
|
114 | do {
|
115 | node = nextNode;
|
116 |
|
117 | if ((node.flags & (Placement | Hydrating)) !== NoFlags) {
|
118 |
|
119 |
|
120 |
|
121 | nearestMounted = node.return;
|
122 | }
|
123 |
|
124 | nextNode = node.return;
|
125 | } while (nextNode);
|
126 | } else {
|
127 | while (node.return) {
|
128 | node = node.return;
|
129 | }
|
130 | }
|
131 |
|
132 | if (node.tag === HostRoot) {
|
133 |
|
134 |
|
135 | return nearestMounted;
|
136 | }
|
137 |
|
138 |
|
139 |
|
140 | return null;
|
141 | }
|
142 |
|
143 | function assertIsMounted(fiber) {
|
144 | if (getNearestMountedFiber(fiber) !== fiber) {
|
145 | throw new Error('Unable to find node on an unmounted component.');
|
146 | }
|
147 | }
|
148 |
|
149 | function findCurrentFiberUsingSlowPath(fiber) {
|
150 | var alternate = fiber.alternate;
|
151 |
|
152 | if (!alternate) {
|
153 |
|
154 | var nearestMounted = getNearestMountedFiber(fiber);
|
155 |
|
156 | if (nearestMounted === null) {
|
157 | throw new Error('Unable to find node on an unmounted component.');
|
158 | }
|
159 |
|
160 | if (nearestMounted !== fiber) {
|
161 | return null;
|
162 | }
|
163 |
|
164 | return fiber;
|
165 | }
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | var a = fiber;
|
171 | var b = alternate;
|
172 |
|
173 | while (true) {
|
174 | var parentA = a.return;
|
175 |
|
176 | if (parentA === null) {
|
177 |
|
178 | break;
|
179 | }
|
180 |
|
181 | var parentB = parentA.alternate;
|
182 |
|
183 | if (parentB === null) {
|
184 |
|
185 |
|
186 |
|
187 |
|
188 | var nextParent = parentA.return;
|
189 |
|
190 | if (nextParent !== null) {
|
191 | a = b = nextParent;
|
192 | continue;
|
193 | }
|
194 |
|
195 |
|
196 | break;
|
197 | }
|
198 |
|
199 |
|
200 |
|
201 |
|
202 | if (parentA.child === parentB.child) {
|
203 | var child = parentA.child;
|
204 |
|
205 | while (child) {
|
206 | if (child === a) {
|
207 |
|
208 | assertIsMounted(parentA);
|
209 | return fiber;
|
210 | }
|
211 |
|
212 | if (child === b) {
|
213 |
|
214 | assertIsMounted(parentA);
|
215 | return alternate;
|
216 | }
|
217 |
|
218 | child = child.sibling;
|
219 | }
|
220 |
|
221 |
|
222 |
|
223 | throw new Error('Unable to find node on an unmounted component.');
|
224 | }
|
225 |
|
226 | if (a.return !== b.return) {
|
227 |
|
228 |
|
229 |
|
230 |
|
231 | a = parentA;
|
232 | b = parentB;
|
233 | } else {
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 | var didFindChild = false;
|
240 | var _child = parentA.child;
|
241 |
|
242 | while (_child) {
|
243 | if (_child === a) {
|
244 | didFindChild = true;
|
245 | a = parentA;
|
246 | b = parentB;
|
247 | break;
|
248 | }
|
249 |
|
250 | if (_child === b) {
|
251 | didFindChild = true;
|
252 | b = parentA;
|
253 | a = parentB;
|
254 | break;
|
255 | }
|
256 |
|
257 | _child = _child.sibling;
|
258 | }
|
259 |
|
260 | if (!didFindChild) {
|
261 |
|
262 | _child = parentB.child;
|
263 |
|
264 | while (_child) {
|
265 | if (_child === a) {
|
266 | didFindChild = true;
|
267 | a = parentB;
|
268 | b = parentA;
|
269 | break;
|
270 | }
|
271 |
|
272 | if (_child === b) {
|
273 | didFindChild = true;
|
274 | b = parentB;
|
275 | a = parentA;
|
276 | break;
|
277 | }
|
278 |
|
279 | _child = _child.sibling;
|
280 | }
|
281 |
|
282 | if (!didFindChild) {
|
283 | throw new Error('Child was not found in either parent set. This indicates a bug ' + 'in React related to the return pointer. Please file an issue.');
|
284 | }
|
285 | }
|
286 | }
|
287 |
|
288 | if (a.alternate !== b) {
|
289 | throw new Error("Return fibers should always be each others' alternates. " + 'This error is likely caused by a bug in React. Please file an issue.');
|
290 | }
|
291 | }
|
292 |
|
293 |
|
294 |
|
295 | if (a.tag !== HostRoot) {
|
296 | throw new Error('Unable to find node on an unmounted component.');
|
297 | }
|
298 |
|
299 | if (a.stateNode.current === a) {
|
300 |
|
301 | return fiber;
|
302 | }
|
303 |
|
304 |
|
305 | return alternate;
|
306 | }
|
307 |
|
308 | var assign = Object.assign;
|
309 |
|
310 | |
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 | function getEventCharCode(nativeEvent) {
|
321 | var charCode;
|
322 | var keyCode = nativeEvent.keyCode;
|
323 |
|
324 | if ('charCode' in nativeEvent) {
|
325 | charCode = nativeEvent.charCode;
|
326 |
|
327 | if (charCode === 0 && keyCode === 13) {
|
328 | charCode = 13;
|
329 | }
|
330 | } else {
|
331 |
|
332 | charCode = keyCode;
|
333 | }
|
334 |
|
335 |
|
336 |
|
337 | if (charCode === 10) {
|
338 | charCode = 13;
|
339 | }
|
340 |
|
341 |
|
342 |
|
343 | if (charCode >= 32 || charCode === 13) {
|
344 | return charCode;
|
345 | }
|
346 |
|
347 | return 0;
|
348 | }
|
349 |
|
350 | function functionThatReturnsTrue() {
|
351 | return true;
|
352 | }
|
353 |
|
354 | function functionThatReturnsFalse() {
|
355 | return false;
|
356 | }
|
357 |
|
358 |
|
359 |
|
360 | function createSyntheticEvent(Interface) {
|
361 | |
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 | function SyntheticBaseEvent(reactName, reactEventType, targetInst, nativeEvent, nativeEventTarget) {
|
375 | this._reactName = reactName;
|
376 | this._targetInst = targetInst;
|
377 | this.type = reactEventType;
|
378 | this.nativeEvent = nativeEvent;
|
379 | this.target = nativeEventTarget;
|
380 | this.currentTarget = null;
|
381 |
|
382 | for (var _propName in Interface) {
|
383 | if (!Interface.hasOwnProperty(_propName)) {
|
384 | continue;
|
385 | }
|
386 |
|
387 | var normalize = Interface[_propName];
|
388 |
|
389 | if (normalize) {
|
390 | this[_propName] = normalize(nativeEvent);
|
391 | } else {
|
392 | this[_propName] = nativeEvent[_propName];
|
393 | }
|
394 | }
|
395 |
|
396 | var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false;
|
397 |
|
398 | if (defaultPrevented) {
|
399 | this.isDefaultPrevented = functionThatReturnsTrue;
|
400 | } else {
|
401 | this.isDefaultPrevented = functionThatReturnsFalse;
|
402 | }
|
403 |
|
404 | this.isPropagationStopped = functionThatReturnsFalse;
|
405 | return this;
|
406 | }
|
407 |
|
408 | assign(SyntheticBaseEvent.prototype, {
|
409 | preventDefault: function () {
|
410 | this.defaultPrevented = true;
|
411 | var event = this.nativeEvent;
|
412 |
|
413 | if (!event) {
|
414 | return;
|
415 | }
|
416 |
|
417 | if (event.preventDefault) {
|
418 | event.preventDefault();
|
419 | } else if (typeof event.returnValue !== 'unknown') {
|
420 | event.returnValue = false;
|
421 | }
|
422 |
|
423 | this.isDefaultPrevented = functionThatReturnsTrue;
|
424 | },
|
425 | stopPropagation: function () {
|
426 | var event = this.nativeEvent;
|
427 |
|
428 | if (!event) {
|
429 | return;
|
430 | }
|
431 |
|
432 | if (event.stopPropagation) {
|
433 | event.stopPropagation();
|
434 | } else if (typeof event.cancelBubble !== 'unknown') {
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 | event.cancelBubble = true;
|
441 | }
|
442 |
|
443 | this.isPropagationStopped = functionThatReturnsTrue;
|
444 | },
|
445 |
|
446 | |
447 |
|
448 |
|
449 |
|
450 |
|
451 | persist: function () {
|
452 | },
|
453 |
|
454 | |
455 |
|
456 |
|
457 |
|
458 |
|
459 | isPersistent: functionThatReturnsTrue
|
460 | });
|
461 | return SyntheticBaseEvent;
|
462 | }
|
463 | |
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 | var EventInterface = {
|
470 | eventPhase: 0,
|
471 | bubbles: 0,
|
472 | cancelable: 0,
|
473 | timeStamp: function (event) {
|
474 | return event.timeStamp || Date.now();
|
475 | },
|
476 | defaultPrevented: 0,
|
477 | isTrusted: 0
|
478 | };
|
479 | var SyntheticEvent = createSyntheticEvent(EventInterface);
|
480 |
|
481 | var UIEventInterface = assign({}, EventInterface, {
|
482 | view: 0,
|
483 | detail: 0
|
484 | });
|
485 |
|
486 | var SyntheticUIEvent = createSyntheticEvent(UIEventInterface);
|
487 | var lastMovementX;
|
488 | var lastMovementY;
|
489 | var lastMouseEvent;
|
490 |
|
491 | function updateMouseMovementPolyfillState(event) {
|
492 | if (event !== lastMouseEvent) {
|
493 | if (lastMouseEvent && event.type === 'mousemove') {
|
494 | lastMovementX = event.screenX - lastMouseEvent.screenX;
|
495 | lastMovementY = event.screenY - lastMouseEvent.screenY;
|
496 | } else {
|
497 | lastMovementX = 0;
|
498 | lastMovementY = 0;
|
499 | }
|
500 |
|
501 | lastMouseEvent = event;
|
502 | }
|
503 | }
|
504 | |
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 | var MouseEventInterface = assign({}, UIEventInterface, {
|
511 | screenX: 0,
|
512 | screenY: 0,
|
513 | clientX: 0,
|
514 | clientY: 0,
|
515 | pageX: 0,
|
516 | pageY: 0,
|
517 | ctrlKey: 0,
|
518 | shiftKey: 0,
|
519 | altKey: 0,
|
520 | metaKey: 0,
|
521 | getModifierState: getEventModifierState,
|
522 | button: 0,
|
523 | buttons: 0,
|
524 | relatedTarget: function (event) {
|
525 | if (event.relatedTarget === undefined) return event.fromElement === event.srcElement ? event.toElement : event.fromElement;
|
526 | return event.relatedTarget;
|
527 | },
|
528 | movementX: function (event) {
|
529 | if ('movementX' in event) {
|
530 | return event.movementX;
|
531 | }
|
532 |
|
533 | updateMouseMovementPolyfillState(event);
|
534 | return lastMovementX;
|
535 | },
|
536 | movementY: function (event) {
|
537 | if ('movementY' in event) {
|
538 | return event.movementY;
|
539 | }
|
540 |
|
541 |
|
542 |
|
543 |
|
544 | return lastMovementY;
|
545 | }
|
546 | });
|
547 |
|
548 | var SyntheticMouseEvent = createSyntheticEvent(MouseEventInterface);
|
549 | |
550 |
|
551 |
|
552 |
|
553 |
|
554 | var DragEventInterface = assign({}, MouseEventInterface, {
|
555 | dataTransfer: 0
|
556 | });
|
557 |
|
558 | var SyntheticDragEvent = createSyntheticEvent(DragEventInterface);
|
559 | |
560 |
|
561 |
|
562 |
|
563 |
|
564 | var FocusEventInterface = assign({}, UIEventInterface, {
|
565 | relatedTarget: 0
|
566 | });
|
567 |
|
568 | var SyntheticFocusEvent = createSyntheticEvent(FocusEventInterface);
|
569 | |
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 | var AnimationEventInterface = assign({}, EventInterface, {
|
576 | animationName: 0,
|
577 | elapsedTime: 0,
|
578 | pseudoElement: 0
|
579 | });
|
580 |
|
581 | var SyntheticAnimationEvent = createSyntheticEvent(AnimationEventInterface);
|
582 | |
583 |
|
584 |
|
585 |
|
586 |
|
587 | var ClipboardEventInterface = assign({}, EventInterface, {
|
588 | clipboardData: function (event) {
|
589 | return 'clipboardData' in event ? event.clipboardData : window.clipboardData;
|
590 | }
|
591 | });
|
592 |
|
593 | var SyntheticClipboardEvent = createSyntheticEvent(ClipboardEventInterface);
|
594 | |
595 |
|
596 |
|
597 |
|
598 |
|
599 | var CompositionEventInterface = assign({}, EventInterface, {
|
600 | data: 0
|
601 | });
|
602 |
|
603 | var SyntheticCompositionEvent = createSyntheticEvent(CompositionEventInterface);
|
604 | |
605 |
|
606 |
|
607 |
|
608 |
|
609 | var normalizeKey = {
|
610 | Esc: 'Escape',
|
611 | Spacebar: ' ',
|
612 | Left: 'ArrowLeft',
|
613 | Up: 'ArrowUp',
|
614 | Right: 'ArrowRight',
|
615 | Down: 'ArrowDown',
|
616 | Del: 'Delete',
|
617 | Win: 'OS',
|
618 | Menu: 'ContextMenu',
|
619 | Apps: 'ContextMenu',
|
620 | Scroll: 'ScrollLock',
|
621 | MozPrintableKey: 'Unidentified'
|
622 | };
|
623 | |
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 | var translateToKey = {
|
630 | '8': 'Backspace',
|
631 | '9': 'Tab',
|
632 | '12': 'Clear',
|
633 | '13': 'Enter',
|
634 | '16': 'Shift',
|
635 | '17': 'Control',
|
636 | '18': 'Alt',
|
637 | '19': 'Pause',
|
638 | '20': 'CapsLock',
|
639 | '27': 'Escape',
|
640 | '32': ' ',
|
641 | '33': 'PageUp',
|
642 | '34': 'PageDown',
|
643 | '35': 'End',
|
644 | '36': 'Home',
|
645 | '37': 'ArrowLeft',
|
646 | '38': 'ArrowUp',
|
647 | '39': 'ArrowRight',
|
648 | '40': 'ArrowDown',
|
649 | '45': 'Insert',
|
650 | '46': 'Delete',
|
651 | '112': 'F1',
|
652 | '113': 'F2',
|
653 | '114': 'F3',
|
654 | '115': 'F4',
|
655 | '116': 'F5',
|
656 | '117': 'F6',
|
657 | '118': 'F7',
|
658 | '119': 'F8',
|
659 | '120': 'F9',
|
660 | '121': 'F10',
|
661 | '122': 'F11',
|
662 | '123': 'F12',
|
663 | '144': 'NumLock',
|
664 | '145': 'ScrollLock',
|
665 | '224': 'Meta'
|
666 | };
|
667 | |
668 |
|
669 |
|
670 |
|
671 |
|
672 | function getEventKey(nativeEvent) {
|
673 | if (nativeEvent.key) {
|
674 |
|
675 |
|
676 |
|
677 |
|
678 | var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
|
679 |
|
680 | if (key !== 'Unidentified') {
|
681 | return key;
|
682 | }
|
683 | }
|
684 |
|
685 |
|
686 | if (nativeEvent.type === 'keypress') {
|
687 | var charCode = getEventCharCode(nativeEvent);
|
688 |
|
689 |
|
690 | return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
|
691 | }
|
692 |
|
693 | if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
|
694 |
|
695 |
|
696 | return translateToKey[nativeEvent.keyCode] || 'Unidentified';
|
697 | }
|
698 |
|
699 | return '';
|
700 | }
|
701 | |
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 | var modifierKeyToProp = {
|
708 | Alt: 'altKey',
|
709 | Control: 'ctrlKey',
|
710 | Meta: 'metaKey',
|
711 | Shift: 'shiftKey'
|
712 | };
|
713 |
|
714 |
|
715 |
|
716 | function modifierStateGetter(keyArg) {
|
717 | var syntheticEvent = this;
|
718 | var nativeEvent = syntheticEvent.nativeEvent;
|
719 |
|
720 | if (nativeEvent.getModifierState) {
|
721 | return nativeEvent.getModifierState(keyArg);
|
722 | }
|
723 |
|
724 | var keyProp = modifierKeyToProp[keyArg];
|
725 | return keyProp ? !!nativeEvent[keyProp] : false;
|
726 | }
|
727 |
|
728 | function getEventModifierState(nativeEvent) {
|
729 | return modifierStateGetter;
|
730 | }
|
731 | |
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 | var KeyboardEventInterface = assign({}, UIEventInterface, {
|
738 | key: getEventKey,
|
739 | code: 0,
|
740 | location: 0,
|
741 | ctrlKey: 0,
|
742 | shiftKey: 0,
|
743 | altKey: 0,
|
744 | metaKey: 0,
|
745 | repeat: 0,
|
746 | locale: 0,
|
747 | getModifierState: getEventModifierState,
|
748 |
|
749 | charCode: function (event) {
|
750 |
|
751 |
|
752 |
|
753 |
|
754 | if (event.type === 'keypress') {
|
755 | return getEventCharCode(event);
|
756 | }
|
757 |
|
758 | return 0;
|
759 | },
|
760 | keyCode: function (event) {
|
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 | if (event.type === 'keydown' || event.type === 'keyup') {
|
768 | return event.keyCode;
|
769 | }
|
770 |
|
771 | return 0;
|
772 | },
|
773 | which: function (event) {
|
774 |
|
775 |
|
776 | if (event.type === 'keypress') {
|
777 | return getEventCharCode(event);
|
778 | }
|
779 |
|
780 | if (event.type === 'keydown' || event.type === 'keyup') {
|
781 | return event.keyCode;
|
782 | }
|
783 |
|
784 | return 0;
|
785 | }
|
786 | });
|
787 |
|
788 | var SyntheticKeyboardEvent = createSyntheticEvent(KeyboardEventInterface);
|
789 | |
790 |
|
791 |
|
792 |
|
793 |
|
794 | var PointerEventInterface = assign({}, MouseEventInterface, {
|
795 | pointerId: 0,
|
796 | width: 0,
|
797 | height: 0,
|
798 | pressure: 0,
|
799 | tangentialPressure: 0,
|
800 | tiltX: 0,
|
801 | tiltY: 0,
|
802 | twist: 0,
|
803 | pointerType: 0,
|
804 | isPrimary: 0
|
805 | });
|
806 |
|
807 | var SyntheticPointerEvent = createSyntheticEvent(PointerEventInterface);
|
808 | |
809 |
|
810 |
|
811 |
|
812 |
|
813 | var TouchEventInterface = assign({}, UIEventInterface, {
|
814 | touches: 0,
|
815 | targetTouches: 0,
|
816 | changedTouches: 0,
|
817 | altKey: 0,
|
818 | metaKey: 0,
|
819 | ctrlKey: 0,
|
820 | shiftKey: 0,
|
821 | getModifierState: getEventModifierState
|
822 | });
|
823 |
|
824 | var SyntheticTouchEvent = createSyntheticEvent(TouchEventInterface);
|
825 | |
826 |
|
827 |
|
828 |
|
829 |
|
830 |
|
831 | var TransitionEventInterface = assign({}, EventInterface, {
|
832 | propertyName: 0,
|
833 | elapsedTime: 0,
|
834 | pseudoElement: 0
|
835 | });
|
836 |
|
837 | var SyntheticTransitionEvent = createSyntheticEvent(TransitionEventInterface);
|
838 | |
839 |
|
840 |
|
841 |
|
842 |
|
843 | var WheelEventInterface = assign({}, MouseEventInterface, {
|
844 | deltaX: function (event) {
|
845 | return 'deltaX' in event ? event.deltaX :
|
846 | 'wheelDeltaX' in event ? -event.wheelDeltaX : 0;
|
847 | },
|
848 | deltaY: function (event) {
|
849 | return 'deltaY' in event ? event.deltaY :
|
850 | 'wheelDeltaY' in event ? -event.wheelDeltaY :
|
851 | 'wheelDelta' in event ? -event.wheelDelta : 0;
|
852 | },
|
853 | deltaZ: 0,
|
854 |
|
855 |
|
856 |
|
857 |
|
858 | deltaMode: 0
|
859 | });
|
860 |
|
861 | var SyntheticWheelEvent = createSyntheticEvent(WheelEventInterface);
|
862 |
|
863 | |
864 |
|
865 |
|
866 | var ELEMENT_NODE = 1;
|
867 |
|
868 | function invokeGuardedCallbackProd(name, func, context, a, b, c, d, e, f) {
|
869 | var funcArgs = Array.prototype.slice.call(arguments, 3);
|
870 |
|
871 | try {
|
872 | func.apply(context, funcArgs);
|
873 | } catch (error) {
|
874 | this.onError(error);
|
875 | }
|
876 | }
|
877 |
|
878 | var invokeGuardedCallbackImpl = invokeGuardedCallbackProd;
|
879 |
|
880 | {
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 | if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
|
902 | var fakeNode = document.createElement('react');
|
903 |
|
904 | invokeGuardedCallbackImpl = function invokeGuardedCallbackDev(name, func, context, a, b, c, d, e, f) {
|
905 |
|
906 |
|
907 |
|
908 |
|
909 | if (typeof document === 'undefined' || document === null) {
|
910 | throw new Error('The `document` global was defined when React was initialized, but is not ' + 'defined anymore. This can happen in a test environment if a component ' + 'schedules an update from an asynchronous callback, but the test has already ' + 'finished running. To solve this, you can either unmount the component at ' + 'the end of your test (and ensure that any asynchronous operations get ' + 'canceled in `componentWillUnmount`), or you can change the test itself ' + 'to be asynchronous.');
|
911 | }
|
912 |
|
913 | var evt = document.createEvent('Event');
|
914 | var didCall = false;
|
915 |
|
916 |
|
917 |
|
918 |
|
919 |
|
920 |
|
921 | var didError = true;
|
922 |
|
923 |
|
924 |
|
925 | var windowEvent = window.event;
|
926 |
|
927 |
|
928 | var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event');
|
929 |
|
930 | function restoreAfterDispatch() {
|
931 |
|
932 |
|
933 |
|
934 |
|
935 | fakeNode.removeEventListener(evtType, callCallback, false);
|
936 |
|
937 |
|
938 |
|
939 |
|
940 | if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
|
941 | window.event = windowEvent;
|
942 | }
|
943 | }
|
944 |
|
945 |
|
946 |
|
947 |
|
948 | var funcArgs = Array.prototype.slice.call(arguments, 3);
|
949 |
|
950 | function callCallback() {
|
951 | didCall = true;
|
952 | restoreAfterDispatch();
|
953 | func.apply(context, funcArgs);
|
954 | didError = false;
|
955 | }
|
956 |
|
957 |
|
958 |
|
959 |
|
960 |
|
961 |
|
962 |
|
963 |
|
964 |
|
965 |
|
966 |
|
967 |
|
968 | var error;
|
969 |
|
970 | var didSetError = false;
|
971 | var isCrossOriginError = false;
|
972 |
|
973 | function handleWindowError(event) {
|
974 | error = event.error;
|
975 | didSetError = true;
|
976 |
|
977 | if (error === null && event.colno === 0 && event.lineno === 0) {
|
978 | isCrossOriginError = true;
|
979 | }
|
980 |
|
981 | if (event.defaultPrevented) {
|
982 |
|
983 |
|
984 |
|
985 | if (error != null && typeof error === 'object') {
|
986 | try {
|
987 | error._suppressLogging = true;
|
988 | } catch (inner) {
|
989 | }
|
990 | }
|
991 | }
|
992 | }
|
993 |
|
994 |
|
995 | var evtType = "react-" + (name ? name : 'invokeguardedcallback');
|
996 |
|
997 | window.addEventListener('error', handleWindowError);
|
998 | fakeNode.addEventListener(evtType, callCallback, false);
|
999 |
|
1000 |
|
1001 | evt.initEvent(evtType, false, false);
|
1002 | fakeNode.dispatchEvent(evt);
|
1003 |
|
1004 | if (windowEventDescriptor) {
|
1005 | Object.defineProperty(window, 'event', windowEventDescriptor);
|
1006 | }
|
1007 |
|
1008 | if (didCall && didError) {
|
1009 | if (!didSetError) {
|
1010 |
|
1011 |
|
1012 | error = new Error('An error was thrown inside one of your components, but React ' + "doesn't know what it was. This is likely due to browser " + 'flakiness. React does its best to preserve the "Pause on ' + 'exceptions" behavior of the DevTools, which requires some ' + "DEV-mode only tricks. It's possible that these don't work in " + 'your browser. Try triggering the error in production mode, ' + 'or switching to a modern browser. If you suspect that this is ' + 'actually an issue with React, please file an issue.');
|
1013 | } else if (isCrossOriginError) {
|
1014 |
|
1015 | error = new Error("A cross-origin error was thrown. React doesn't have access to " + 'the actual error object in development. ' + 'See https://reactjs.org/link/crossorigin-error for more information.');
|
1016 | }
|
1017 |
|
1018 | this.onError(error);
|
1019 | }
|
1020 |
|
1021 |
|
1022 | window.removeEventListener('error', handleWindowError);
|
1023 |
|
1024 | if (!didCall) {
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 | restoreAfterDispatch();
|
1030 | return invokeGuardedCallbackProd.apply(this, arguments);
|
1031 | }
|
1032 | };
|
1033 | }
|
1034 | }
|
1035 |
|
1036 | var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
|
1037 |
|
1038 | var hasError = false;
|
1039 | var caughtError = null;
|
1040 |
|
1041 | var hasRethrowError = false;
|
1042 | var rethrowError = null;
|
1043 | var reporter = {
|
1044 | onError: function (error) {
|
1045 | hasError = true;
|
1046 | caughtError = error;
|
1047 | }
|
1048 | };
|
1049 | |
1050 |
|
1051 |
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 | function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
|
1064 | hasError = false;
|
1065 | caughtError = null;
|
1066 | invokeGuardedCallbackImpl$1.apply(reporter, arguments);
|
1067 | }
|
1068 | |
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 | function invokeGuardedCallbackAndCatchFirstError(name, func, context, a, b, c, d, e, f) {
|
1080 | invokeGuardedCallback.apply(this, arguments);
|
1081 |
|
1082 | if (hasError) {
|
1083 | var error = clearCaughtError();
|
1084 |
|
1085 | if (!hasRethrowError) {
|
1086 | hasRethrowError = true;
|
1087 | rethrowError = error;
|
1088 | }
|
1089 | }
|
1090 | }
|
1091 | |
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 | function rethrowCaughtError() {
|
1097 | if (hasRethrowError) {
|
1098 | var error = rethrowError;
|
1099 | hasRethrowError = false;
|
1100 | rethrowError = null;
|
1101 | throw error;
|
1102 | }
|
1103 | }
|
1104 | function clearCaughtError() {
|
1105 | if (hasError) {
|
1106 | var error = caughtError;
|
1107 | hasError = false;
|
1108 | caughtError = null;
|
1109 | return error;
|
1110 | } else {
|
1111 | throw new Error('clearCaughtError was called but no error was captured. This error ' + 'is likely caused by a bug in React. Please file an issue.');
|
1112 | }
|
1113 | }
|
1114 |
|
1115 | var isArrayImpl = Array.isArray;
|
1116 |
|
1117 | function isArray(a) {
|
1118 | return isArrayImpl(a);
|
1119 | }
|
1120 |
|
1121 | var SecretInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
1122 | var EventInternals = SecretInternals.Events;
|
1123 | var getInstanceFromNode = EventInternals[0];
|
1124 | var getNodeFromInstance = EventInternals[1];
|
1125 | var getFiberCurrentPropsFromNode = EventInternals[2];
|
1126 | var enqueueStateRestore = EventInternals[3];
|
1127 | var restoreStateIfNeeded = EventInternals[4];
|
1128 | var reactAct = React.unstable_act;
|
1129 |
|
1130 | function Event(suffix) {}
|
1131 |
|
1132 | var hasWarnedAboutDeprecatedMockComponent = false;
|
1133 | |
1134 |
|
1135 |
|
1136 |
|
1137 | function findAllInRenderedFiberTreeInternal(fiber, test) {
|
1138 | if (!fiber) {
|
1139 | return [];
|
1140 | }
|
1141 |
|
1142 | var currentParent = findCurrentFiberUsingSlowPath(fiber);
|
1143 |
|
1144 | if (!currentParent) {
|
1145 | return [];
|
1146 | }
|
1147 |
|
1148 | var node = currentParent;
|
1149 | var ret = [];
|
1150 |
|
1151 | while (true) {
|
1152 | if (node.tag === HostComponent || node.tag === HostText || node.tag === ClassComponent || node.tag === FunctionComponent) {
|
1153 | var publicInst = node.stateNode;
|
1154 |
|
1155 | if (test(publicInst)) {
|
1156 | ret.push(publicInst);
|
1157 | }
|
1158 | }
|
1159 |
|
1160 | if (node.child) {
|
1161 | node.child.return = node;
|
1162 | node = node.child;
|
1163 | continue;
|
1164 | }
|
1165 |
|
1166 | if (node === currentParent) {
|
1167 | return ret;
|
1168 | }
|
1169 |
|
1170 | while (!node.sibling) {
|
1171 | if (!node.return || node.return === currentParent) {
|
1172 | return ret;
|
1173 | }
|
1174 |
|
1175 | node = node.return;
|
1176 | }
|
1177 |
|
1178 | node.sibling.return = node.return;
|
1179 | node = node.sibling;
|
1180 | }
|
1181 | }
|
1182 |
|
1183 | function validateClassInstance(inst, methodName) {
|
1184 | if (!inst) {
|
1185 |
|
1186 | return;
|
1187 | }
|
1188 |
|
1189 | if (get(inst)) {
|
1190 |
|
1191 | return;
|
1192 | }
|
1193 |
|
1194 | var received;
|
1195 | var stringified = String(inst);
|
1196 |
|
1197 | if (isArray(inst)) {
|
1198 | received = 'an array';
|
1199 | } else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
|
1200 | received = 'a DOM node';
|
1201 | } else if (stringified === '[object Object]') {
|
1202 | received = 'object with keys {' + Object.keys(inst).join(', ') + '}';
|
1203 | } else {
|
1204 | received = stringified;
|
1205 | }
|
1206 |
|
1207 | throw new Error(methodName + "(...): the first argument must be a React class instance. " + ("Instead received: " + received + "."));
|
1208 | }
|
1209 | |
1210 |
|
1211 |
|
1212 |
|
1213 |
|
1214 |
|
1215 |
|
1216 |
|
1217 |
|
1218 |
|
1219 |
|
1220 | var didWarnAboutReactTestUtilsDeprecation = false;
|
1221 |
|
1222 | function renderIntoDocument(element) {
|
1223 | {
|
1224 | if (!didWarnAboutReactTestUtilsDeprecation) {
|
1225 | didWarnAboutReactTestUtilsDeprecation = true;
|
1226 |
|
1227 | error('ReactDOMTestUtils is deprecated and will be removed in a future ' + 'major release, because it exposes internal implementation details ' + 'that are highly likely to change between releases. Upgrade to a ' + 'modern testing library, such as @testing-library/react. See ' + 'https://react.dev/warnings/react-dom-test-utils for more info.');
|
1228 | }
|
1229 | }
|
1230 |
|
1231 | var div = document.createElement('div');
|
1232 |
|
1233 |
|
1234 |
|
1235 |
|
1236 |
|
1237 | return ReactDOM.render(element, div);
|
1238 | }
|
1239 |
|
1240 | function isElement(element) {
|
1241 | return React.isValidElement(element);
|
1242 | }
|
1243 |
|
1244 | function isElementOfType(inst, convenienceConstructor) {
|
1245 | return React.isValidElement(inst) && inst.type === convenienceConstructor;
|
1246 | }
|
1247 |
|
1248 | function isDOMComponent(inst) {
|
1249 | return !!(inst && inst.nodeType === ELEMENT_NODE && inst.tagName);
|
1250 | }
|
1251 |
|
1252 | function isDOMComponentElement(inst) {
|
1253 | return !!(inst && React.isValidElement(inst) && !!inst.tagName);
|
1254 | }
|
1255 |
|
1256 | function isCompositeComponent(inst) {
|
1257 | if (isDOMComponent(inst)) {
|
1258 |
|
1259 |
|
1260 | return false;
|
1261 | }
|
1262 |
|
1263 | return inst != null && typeof inst.render === 'function' && typeof inst.setState === 'function';
|
1264 | }
|
1265 |
|
1266 | function isCompositeComponentWithType(inst, type) {
|
1267 | if (!isCompositeComponent(inst)) {
|
1268 | return false;
|
1269 | }
|
1270 |
|
1271 | var internalInstance = get(inst);
|
1272 | var constructor = internalInstance.type;
|
1273 | return constructor === type;
|
1274 | }
|
1275 |
|
1276 | function findAllInRenderedTree(inst, test) {
|
1277 | validateClassInstance(inst, 'findAllInRenderedTree');
|
1278 |
|
1279 | if (!inst) {
|
1280 | return [];
|
1281 | }
|
1282 |
|
1283 | var internalInstance = get(inst);
|
1284 | return findAllInRenderedFiberTreeInternal(internalInstance, test);
|
1285 | }
|
1286 | /**
|
1287 | * Finds all instances of components in the rendered tree that are DOM
|
1288 | * components with the class name matching `className`.
|
1289 | * @return {array} an array of all the matches.
|
1290 | */
|
1291 |
|
1292 |
|
1293 | function scryRenderedDOMComponentsWithClass(root, classNames) {
|
1294 | validateClassInstance(root, 'scryRenderedDOMComponentsWithClass');
|
1295 | return findAllInRenderedTree(root, function (inst) {
|
1296 | if (isDOMComponent(inst)) {
|
1297 | var className = inst.className;
|
1298 |
|
1299 | if (typeof className !== 'string') {
|
1300 |
|
1301 | className = inst.getAttribute('class') || '';
|
1302 | }
|
1303 |
|
1304 | var classList = className.split(/\s+/);
|
1305 |
|
1306 | if (!isArray(classNames)) {
|
1307 | if (classNames === undefined) {
|
1308 | throw new Error('TestUtils.scryRenderedDOMComponentsWithClass expects a ' + 'className as a second argument.');
|
1309 | }
|
1310 |
|
1311 | classNames = classNames.split(/\s+/);
|
1312 | }
|
1313 |
|
1314 | return classNames.every(function (name) {
|
1315 | return classList.indexOf(name) !== -1;
|
1316 | });
|
1317 | }
|
1318 |
|
1319 | return false;
|
1320 | });
|
1321 | }
|
1322 | |
1323 |
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 | function findRenderedDOMComponentWithClass(root, className) {
|
1331 | validateClassInstance(root, 'findRenderedDOMComponentWithClass');
|
1332 | var all = scryRenderedDOMComponentsWithClass(root, className);
|
1333 |
|
1334 | if (all.length !== 1) {
|
1335 | throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for class:' + className);
|
1336 | }
|
1337 |
|
1338 | return all[0];
|
1339 | }
|
1340 | |
1341 |
|
1342 |
|
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 | function scryRenderedDOMComponentsWithTag(root, tagName) {
|
1348 | validateClassInstance(root, 'scryRenderedDOMComponentsWithTag');
|
1349 | return findAllInRenderedTree(root, function (inst) {
|
1350 | return isDOMComponent(inst) && inst.tagName.toUpperCase() === tagName.toUpperCase();
|
1351 | });
|
1352 | }
|
1353 | |
1354 |
|
1355 |
|
1356 |
|
1357 |
|
1358 |
|
1359 |
|
1360 |
|
1361 | function findRenderedDOMComponentWithTag(root, tagName) {
|
1362 | validateClassInstance(root, 'findRenderedDOMComponentWithTag');
|
1363 | var all = scryRenderedDOMComponentsWithTag(root, tagName);
|
1364 |
|
1365 | if (all.length !== 1) {
|
1366 | throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for tag:' + tagName);
|
1367 | }
|
1368 |
|
1369 | return all[0];
|
1370 | }
|
1371 | |
1372 |
|
1373 |
|
1374 |
|
1375 |
|
1376 |
|
1377 | function scryRenderedComponentsWithType(root, componentType) {
|
1378 | validateClassInstance(root, 'scryRenderedComponentsWithType');
|
1379 | return findAllInRenderedTree(root, function (inst) {
|
1380 | return isCompositeComponentWithType(inst, componentType);
|
1381 | });
|
1382 | }
|
1383 | |
1384 |
|
1385 |
|
1386 |
|
1387 |
|
1388 |
|
1389 |
|
1390 |
|
1391 | function findRenderedComponentWithType(root, componentType) {
|
1392 | validateClassInstance(root, 'findRenderedComponentWithType');
|
1393 | var all = scryRenderedComponentsWithType(root, componentType);
|
1394 |
|
1395 | if (all.length !== 1) {
|
1396 | throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for componentType:' + componentType);
|
1397 | }
|
1398 |
|
1399 | return all[0];
|
1400 | }
|
1401 | |
1402 |
|
1403 |
|
1404 |
|
1405 |
|
1406 |
|
1407 |
|
1408 |
|
1409 |
|
1410 |
|
1411 |
|
1412 |
|
1413 |
|
1414 |
|
1415 |
|
1416 | function mockComponent(module, mockTagName) {
|
1417 | {
|
1418 | if (!hasWarnedAboutDeprecatedMockComponent) {
|
1419 | hasWarnedAboutDeprecatedMockComponent = true;
|
1420 |
|
1421 | warn('ReactTestUtils.mockComponent() is deprecated. ' + 'Use shallow rendering or jest.mock() instead.\n\n' + 'See https://reactjs.org/link/test-utils-mock-component for more information.');
|
1422 | }
|
1423 | }
|
1424 |
|
1425 | mockTagName = mockTagName || module.mockTagName || 'div';
|
1426 | module.prototype.render.mockImplementation(function () {
|
1427 | return React.createElement(mockTagName, null, this.props.children);
|
1428 | });
|
1429 | return this;
|
1430 | }
|
1431 |
|
1432 | function nativeTouchData(x, y) {
|
1433 | return {
|
1434 | touches: [{
|
1435 | pageX: x,
|
1436 | pageY: y
|
1437 | }]
|
1438 | };
|
1439 | }
|
1440 |
|
1441 |
|
1442 |
|
1443 | |
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 | function executeDispatch(event, listener, inst) {
|
1452 | var type = event.type || 'unknown-event';
|
1453 | event.currentTarget = getNodeFromInstance(inst);
|
1454 | invokeGuardedCallbackAndCatchFirstError(type, listener, undefined, event);
|
1455 | event.currentTarget = null;
|
1456 | }
|
1457 | |
1458 |
|
1459 |
|
1460 |
|
1461 |
|
1462 | function executeDispatchesInOrder(event) {
|
1463 | var dispatchListeners = event._dispatchListeners;
|
1464 | var dispatchInstances = event._dispatchInstances;
|
1465 |
|
1466 | if (isArray(dispatchListeners)) {
|
1467 | for (var i = 0; i < dispatchListeners.length; i++) {
|
1468 | if (event.isPropagationStopped()) {
|
1469 | break;
|
1470 | }
|
1471 |
|
1472 |
|
1473 | executeDispatch(event, dispatchListeners[i], dispatchInstances[i]);
|
1474 | }
|
1475 | } else if (dispatchListeners) {
|
1476 | executeDispatch(event, dispatchListeners, dispatchInstances);
|
1477 | }
|
1478 |
|
1479 | event._dispatchListeners = null;
|
1480 | event._dispatchInstances = null;
|
1481 | }
|
1482 | |
1483 |
|
1484 |
|
1485 |
|
1486 |
|
1487 |
|
1488 |
|
1489 |
|
1490 | var executeDispatchesAndRelease = function (event) {
|
1491 | if (event) {
|
1492 | executeDispatchesInOrder(event);
|
1493 |
|
1494 | if (!event.isPersistent()) {
|
1495 | event.constructor.release(event);
|
1496 | }
|
1497 | }
|
1498 | };
|
1499 |
|
1500 | function isInteractive(tag) {
|
1501 | return tag === 'button' || tag === 'input' || tag === 'select' || tag === 'textarea';
|
1502 | }
|
1503 |
|
1504 | function getParent(inst) {
|
1505 | do {
|
1506 | inst = inst.return;
|
1507 |
|
1508 |
|
1509 |
|
1510 |
|
1511 | } while (inst && inst.tag !== HostComponent);
|
1512 |
|
1513 | if (inst) {
|
1514 | return inst;
|
1515 | }
|
1516 |
|
1517 | return null;
|
1518 | }
|
1519 | |
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 | function traverseTwoPhase(inst, fn, arg) {
|
1525 | var path = [];
|
1526 |
|
1527 | while (inst) {
|
1528 | path.push(inst);
|
1529 | inst = getParent(inst);
|
1530 | }
|
1531 |
|
1532 | var i;
|
1533 |
|
1534 | for (i = path.length; i-- > 0;) {
|
1535 | fn(path[i], 'captured', arg);
|
1536 | }
|
1537 |
|
1538 | for (i = 0; i < path.length; i++) {
|
1539 | fn(path[i], 'bubbled', arg);
|
1540 | }
|
1541 | }
|
1542 |
|
1543 | function shouldPreventMouseEvent(name, type, props) {
|
1544 | switch (name) {
|
1545 | case 'onClick':
|
1546 | case 'onClickCapture':
|
1547 | case 'onDoubleClick':
|
1548 | case 'onDoubleClickCapture':
|
1549 | case 'onMouseDown':
|
1550 | case 'onMouseDownCapture':
|
1551 | case 'onMouseMove':
|
1552 | case 'onMouseMoveCapture':
|
1553 | case 'onMouseUp':
|
1554 | case 'onMouseUpCapture':
|
1555 | case 'onMouseEnter':
|
1556 | return !!(props.disabled && isInteractive(type));
|
1557 |
|
1558 | default:
|
1559 | return false;
|
1560 | }
|
1561 | }
|
1562 | |
1563 |
|
1564 |
|
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 | function getListener(inst, registrationName) {
|
1570 |
|
1571 |
|
1572 | var stateNode = inst.stateNode;
|
1573 |
|
1574 | if (!stateNode) {
|
1575 |
|
1576 | return null;
|
1577 | }
|
1578 |
|
1579 | var props = getFiberCurrentPropsFromNode(stateNode);
|
1580 |
|
1581 | if (!props) {
|
1582 |
|
1583 | return null;
|
1584 | }
|
1585 |
|
1586 | var listener = props[registrationName];
|
1587 |
|
1588 | if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
|
1589 | return null;
|
1590 | }
|
1591 |
|
1592 | if (listener && typeof listener !== 'function') {
|
1593 | throw new Error("Expected `" + registrationName + "` listener to be a function, instead got a value of `" + typeof listener + "` type.");
|
1594 | }
|
1595 |
|
1596 | return listener;
|
1597 | }
|
1598 |
|
1599 | function listenerAtPhase(inst, event, propagationPhase) {
|
1600 | var registrationName = event._reactName;
|
1601 |
|
1602 | if (propagationPhase === 'captured') {
|
1603 | registrationName += 'Capture';
|
1604 | }
|
1605 |
|
1606 | return getListener(inst, registrationName);
|
1607 | }
|
1608 |
|
1609 | function accumulateDispatches(inst, ignoredDirection, event) {
|
1610 | if (inst && event && event._reactName) {
|
1611 | var registrationName = event._reactName;
|
1612 | var listener = getListener(inst, registrationName);
|
1613 |
|
1614 | if (listener) {
|
1615 | if (event._dispatchListeners == null) {
|
1616 | event._dispatchListeners = [];
|
1617 | }
|
1618 |
|
1619 | if (event._dispatchInstances == null) {
|
1620 | event._dispatchInstances = [];
|
1621 | }
|
1622 |
|
1623 | event._dispatchListeners.push(listener);
|
1624 |
|
1625 | event._dispatchInstances.push(inst);
|
1626 | }
|
1627 | }
|
1628 | }
|
1629 |
|
1630 | function accumulateDirectionalDispatches(inst, phase, event) {
|
1631 | {
|
1632 | if (!inst) {
|
1633 | error('Dispatching inst must not be null');
|
1634 | }
|
1635 | }
|
1636 |
|
1637 | var listener = listenerAtPhase(inst, event, phase);
|
1638 |
|
1639 | if (listener) {
|
1640 | if (event._dispatchListeners == null) {
|
1641 | event._dispatchListeners = [];
|
1642 | }
|
1643 |
|
1644 | if (event._dispatchInstances == null) {
|
1645 | event._dispatchInstances = [];
|
1646 | }
|
1647 |
|
1648 | event._dispatchListeners.push(listener);
|
1649 |
|
1650 | event._dispatchInstances.push(inst);
|
1651 | }
|
1652 | }
|
1653 |
|
1654 | function accumulateDirectDispatchesSingle(event) {
|
1655 | if (event && event._reactName) {
|
1656 | accumulateDispatches(event._targetInst, null, event);
|
1657 | }
|
1658 | }
|
1659 |
|
1660 | function accumulateTwoPhaseDispatchesSingle(event) {
|
1661 | if (event && event._reactName) {
|
1662 | traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
|
1663 | }
|
1664 | }
|
1665 |
|
1666 |
|
1667 | var Simulate = {};
|
1668 | var directDispatchEventTypes = new Set(['mouseEnter', 'mouseLeave', 'pointerEnter', 'pointerLeave']);
|
1669 | |
1670 |
|
1671 |
|
1672 |
|
1673 |
|
1674 |
|
1675 |
|
1676 |
|
1677 |
|
1678 | function makeSimulator(eventType) {
|
1679 | return function (domNode, eventData) {
|
1680 | if (React.isValidElement(domNode)) {
|
1681 | throw new 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.');
|
1682 | }
|
1683 |
|
1684 | if (isCompositeComponent(domNode)) {
|
1685 | throw new 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.');
|
1686 | }
|
1687 |
|
1688 | var reactName = 'on' + eventType[0].toUpperCase() + eventType.slice(1);
|
1689 | var fakeNativeEvent = new Event();
|
1690 | fakeNativeEvent.target = domNode;
|
1691 | fakeNativeEvent.type = eventType.toLowerCase();
|
1692 | var targetInst = getInstanceFromNode(domNode);
|
1693 | var event = new SyntheticEvent(reactName, fakeNativeEvent.type, targetInst, fakeNativeEvent, domNode);
|
1694 |
|
1695 |
|
1696 | event.persist();
|
1697 | assign(event, eventData);
|
1698 |
|
1699 | if (directDispatchEventTypes.has(eventType)) {
|
1700 | accumulateDirectDispatchesSingle(event);
|
1701 | } else {
|
1702 | accumulateTwoPhaseDispatchesSingle(event);
|
1703 | }
|
1704 |
|
1705 | ReactDOM.unstable_batchedUpdates(function () {
|
1706 |
|
1707 |
|
1708 | enqueueStateRestore(domNode);
|
1709 | executeDispatchesAndRelease(event);
|
1710 | rethrowCaughtError();
|
1711 | });
|
1712 | restoreStateIfNeeded();
|
1713 | };
|
1714 | }
|
1715 |
|
1716 |
|
1717 | var simulatedEventTypes = ['blur', 'cancel', 'click', 'close', 'contextMenu', 'copy', 'cut', 'auxClick', 'doubleClick', 'dragEnd', 'dragStart', 'drop', 'focus', 'input', 'invalid', 'keyDown', 'keyPress', 'keyUp', 'mouseDown', 'mouseUp', 'paste', 'pause', 'play', 'pointerCancel', 'pointerDown', 'pointerUp', 'rateChange', 'reset', 'resize', 'seeked', 'submit', 'touchCancel', 'touchEnd', 'touchStart', 'volumeChange', 'drag', 'dragEnter', 'dragExit', 'dragLeave', 'dragOver', 'mouseMove', 'mouseOut', 'mouseOver', 'pointerMove', 'pointerOut', 'pointerOver', 'scroll', 'toggle', 'touchMove', 'wheel', 'abort', 'animationEnd', 'animationIteration', 'animationStart', 'canPlay', 'canPlayThrough', 'durationChange', 'emptied', 'encrypted', 'ended', 'error', 'gotPointerCapture', 'load', 'loadedData', 'loadedMetadata', 'loadStart', 'lostPointerCapture', 'playing', 'progress', 'seeking', 'stalled', 'suspend', 'timeUpdate', 'transitionEnd', 'waiting', 'mouseEnter', 'mouseLeave', 'pointerEnter', 'pointerLeave', 'change', 'select', 'beforeInput', 'compositionEnd', 'compositionStart', 'compositionUpdate'];
|
1718 |
|
1719 | function buildSimulators() {
|
1720 | simulatedEventTypes.forEach(function (eventType) {
|
1721 | Simulate[eventType] = makeSimulator(eventType);
|
1722 | });
|
1723 | }
|
1724 |
|
1725 | buildSimulators();
|
1726 | var didWarnAboutUsingAct = false;
|
1727 | var act = function actWithWarning(callback) {
|
1728 | {
|
1729 | if (!didWarnAboutUsingAct) {
|
1730 | didWarnAboutUsingAct = true;
|
1731 |
|
1732 | error('`ReactDOMTestUtils.act` is deprecated in favor of `React.act`. ' + 'Import `act` from `react` instead of `react-dom/test-utils`. ' + 'See https://react.dev/warnings/react-dom-test-utils for more info.');
|
1733 | }
|
1734 | }
|
1735 |
|
1736 | return reactAct(callback);
|
1737 | } ;
|
1738 |
|
1739 | exports.Simulate = Simulate;
|
1740 | exports.act = act;
|
1741 | exports.findAllInRenderedTree = findAllInRenderedTree;
|
1742 | exports.findRenderedComponentWithType = findRenderedComponentWithType;
|
1743 | exports.findRenderedDOMComponentWithClass = findRenderedDOMComponentWithClass;
|
1744 | exports.findRenderedDOMComponentWithTag = findRenderedDOMComponentWithTag;
|
1745 | exports.isCompositeComponent = isCompositeComponent;
|
1746 | exports.isCompositeComponentWithType = isCompositeComponentWithType;
|
1747 | exports.isDOMComponent = isDOMComponent;
|
1748 | exports.isDOMComponentElement = isDOMComponentElement;
|
1749 | exports.isElement = isElement;
|
1750 | exports.isElementOfType = isElementOfType;
|
1751 | exports.mockComponent = mockComponent;
|
1752 | exports.nativeTouchData = nativeTouchData;
|
1753 | exports.renderIntoDocument = renderIntoDocument;
|
1754 | exports.scryRenderedComponentsWithType = scryRenderedComponentsWithType;
|
1755 | exports.scryRenderedDOMComponentsWithClass = scryRenderedDOMComponentsWithClass;
|
1756 | exports.scryRenderedDOMComponentsWithTag = scryRenderedDOMComponentsWithTag;
|
1757 | exports.traverseTwoPhase = traverseTwoPhase;
|
1758 |
|
1759 | })));
|