UNPKG

73.2 kBJavaScriptView Raw
1/** @license React v17.0.1
2 * react-dom-test-utils.development.js
3 *
4 * Copyright (c) Facebook, Inc. and its affiliates.
5 *
6 * This source code is licensed under the MIT license found in the
7 * LICENSE file in the root directory of this source tree.
8 */
9(function (global, factory) {
10 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-dom')) :
11 typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-dom'], factory) :
12 (global = global || self, factory(global.ReactTestUtils = {}, global.React, global.ReactDOM));
13}(this, (function (exports, React, ReactDOM) { 'use strict';
14
15 var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
16 var _assign = ReactInternals.assign;
17
18 var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
19
20 // by calls to these methods by a Babel plugin.
21 //
22 // In PROD (or in packages without access to React internals),
23 // they are left as they are instead.
24
25 function warn(format) {
26 {
27 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
28 args[_key - 1] = arguments[_key];
29 }
30
31 printWarning('warn', format, args);
32 }
33 }
34 function error(format) {
35 {
36 for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
37 args[_key2 - 1] = arguments[_key2];
38 }
39
40 printWarning('error', format, args);
41 }
42 }
43
44 function printWarning(level, format, args) {
45 // When changing this logic, you might want to also
46 // update consoleWithStackDev.www.js as well.
47 {
48 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
49 var stack = ReactDebugCurrentFrame.getStackAddendum();
50
51 if (stack !== '') {
52 format += '%s';
53 args = args.concat([stack]);
54 }
55
56 var argsWithFormat = args.map(function (item) {
57 return '' + item;
58 }); // Careful: RN currently depends on this prefix
59
60 argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
61 // breaks IE9: https://github.com/facebook/react/issues/13610
62 // eslint-disable-next-line react-internal/no-production-logging
63
64 Function.prototype.apply.call(console[level], console, argsWithFormat);
65 }
66 }
67
68 /**
69 * `ReactInstanceMap` maintains a mapping from a public facing stateful
70 * instance (key) and the internal representation (value). This allows public
71 * methods to accept the user facing instance as an argument and map them back
72 * to internal methods.
73 *
74 * Note that this module is currently shared and assumed to be stateless.
75 * If this becomes an actual Map, that will break.
76 */
77 function get(key) {
78 return key._reactInternals;
79 }
80
81 // ATTENTION
82 // When adding new symbols to this file,
83 // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
84 // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
85 // nor polyfill, then a plain number is used for performance.
86 var REACT_ELEMENT_TYPE = 0xeac7;
87 var REACT_PORTAL_TYPE = 0xeaca;
88 var REACT_FRAGMENT_TYPE = 0xeacb;
89 var REACT_STRICT_MODE_TYPE = 0xeacc;
90 var REACT_PROFILER_TYPE = 0xead2;
91 var REACT_PROVIDER_TYPE = 0xeacd;
92 var REACT_CONTEXT_TYPE = 0xeace;
93 var REACT_FORWARD_REF_TYPE = 0xead0;
94 var REACT_SUSPENSE_TYPE = 0xead1;
95 var REACT_SUSPENSE_LIST_TYPE = 0xead8;
96 var REACT_MEMO_TYPE = 0xead3;
97 var REACT_LAZY_TYPE = 0xead4;
98 var REACT_BLOCK_TYPE = 0xead9;
99 var REACT_SERVER_BLOCK_TYPE = 0xeada;
100 var REACT_FUNDAMENTAL_TYPE = 0xead5;
101 var REACT_SCOPE_TYPE = 0xead7;
102 var REACT_OPAQUE_ID_TYPE = 0xeae0;
103 var REACT_DEBUG_TRACING_MODE_TYPE = 0xeae1;
104 var REACT_OFFSCREEN_TYPE = 0xeae2;
105 var REACT_LEGACY_HIDDEN_TYPE = 0xeae3;
106
107 if (typeof Symbol === 'function' && Symbol.for) {
108 var symbolFor = Symbol.for;
109 REACT_ELEMENT_TYPE = symbolFor('react.element');
110 REACT_PORTAL_TYPE = symbolFor('react.portal');
111 REACT_FRAGMENT_TYPE = symbolFor('react.fragment');
112 REACT_STRICT_MODE_TYPE = symbolFor('react.strict_mode');
113 REACT_PROFILER_TYPE = symbolFor('react.profiler');
114 REACT_PROVIDER_TYPE = symbolFor('react.provider');
115 REACT_CONTEXT_TYPE = symbolFor('react.context');
116 REACT_FORWARD_REF_TYPE = symbolFor('react.forward_ref');
117 REACT_SUSPENSE_TYPE = symbolFor('react.suspense');
118 REACT_SUSPENSE_LIST_TYPE = symbolFor('react.suspense_list');
119 REACT_MEMO_TYPE = symbolFor('react.memo');
120 REACT_LAZY_TYPE = symbolFor('react.lazy');
121 REACT_BLOCK_TYPE = symbolFor('react.block');
122 REACT_SERVER_BLOCK_TYPE = symbolFor('react.server.block');
123 REACT_FUNDAMENTAL_TYPE = symbolFor('react.fundamental');
124 REACT_SCOPE_TYPE = symbolFor('react.scope');
125 REACT_OPAQUE_ID_TYPE = symbolFor('react.opaque.id');
126 REACT_DEBUG_TRACING_MODE_TYPE = symbolFor('react.debug_trace_mode');
127 REACT_OFFSCREEN_TYPE = symbolFor('react.offscreen');
128 REACT_LEGACY_HIDDEN_TYPE = symbolFor('react.legacy_hidden');
129 }
130
131 var FunctionComponent = 0;
132 var ClassComponent = 1;
133
134 var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
135
136 var HostComponent = 5;
137 var HostText = 6;
138
139 // Don't change these two values. They're used by React Dev Tools.
140 var NoFlags =
141 /* */
142 0;
143
144 var Placement =
145 /* */
146 2;
147 var Hydrating =
148 /* */
149 1024;
150
151 var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
152 function getNearestMountedFiber(fiber) {
153 var node = fiber;
154 var nearestMounted = fiber;
155
156 if (!fiber.alternate) {
157 // If there is no alternate, this might be a new tree that isn't inserted
158 // yet. If it is, then it will have a pending insertion effect on it.
159 var nextNode = node;
160
161 do {
162 node = nextNode;
163
164 if ((node.flags & (Placement | Hydrating)) !== NoFlags) {
165 // This is an insertion or in-progress hydration. The nearest possible
166 // mounted fiber is the parent but we need to continue to figure out
167 // if that one is still mounted.
168 nearestMounted = node.return;
169 }
170
171 nextNode = node.return;
172 } while (nextNode);
173 } else {
174 while (node.return) {
175 node = node.return;
176 }
177 }
178
179 if (node.tag === HostRoot) {
180 // TODO: Check if this was a nested HostRoot when used with
181 // renderContainerIntoSubtree.
182 return nearestMounted;
183 } // If we didn't hit the root, that means that we're in an disconnected tree
184 // that has been unmounted.
185
186
187 return null;
188 }
189
190 function assertIsMounted(fiber) {
191 if (!(getNearestMountedFiber(fiber) === fiber)) {
192 {
193 throw Error( "Unable to find node on an unmounted component." );
194 }
195 }
196 }
197
198 function findCurrentFiberUsingSlowPath(fiber) {
199 var alternate = fiber.alternate;
200
201 if (!alternate) {
202 // If there is no alternate, then we only need to check if it is mounted.
203 var nearestMounted = getNearestMountedFiber(fiber);
204
205 if (!(nearestMounted !== null)) {
206 {
207 throw Error( "Unable to find node on an unmounted component." );
208 }
209 }
210
211 if (nearestMounted !== fiber) {
212 return null;
213 }
214
215 return fiber;
216 } // If we have two possible branches, we'll walk backwards up to the root
217 // to see what path the root points to. On the way we may hit one of the
218 // special cases and we'll deal with them.
219
220
221 var a = fiber;
222 var b = alternate;
223
224 while (true) {
225 var parentA = a.return;
226
227 if (parentA === null) {
228 // We're at the root.
229 break;
230 }
231
232 var parentB = parentA.alternate;
233
234 if (parentB === null) {
235 // There is no alternate. This is an unusual case. Currently, it only
236 // happens when a Suspense component is hidden. An extra fragment fiber
237 // is inserted in between the Suspense fiber and its children. Skip
238 // over this extra fragment fiber and proceed to the next parent.
239 var nextParent = parentA.return;
240
241 if (nextParent !== null) {
242 a = b = nextParent;
243 continue;
244 } // If there's no parent, we're at the root.
245
246
247 break;
248 } // If both copies of the parent fiber point to the same child, we can
249 // assume that the child is current. This happens when we bailout on low
250 // priority: the bailed out fiber's child reuses the current child.
251
252
253 if (parentA.child === parentB.child) {
254 var child = parentA.child;
255
256 while (child) {
257 if (child === a) {
258 // We've determined that A is the current branch.
259 assertIsMounted(parentA);
260 return fiber;
261 }
262
263 if (child === b) {
264 // We've determined that B is the current branch.
265 assertIsMounted(parentA);
266 return alternate;
267 }
268
269 child = child.sibling;
270 } // We should never have an alternate for any mounting node. So the only
271 // way this could possibly happen is if this was unmounted, if at all.
272
273
274 {
275 {
276 throw Error( "Unable to find node on an unmounted component." );
277 }
278 }
279 }
280
281 if (a.return !== b.return) {
282 // The return pointer of A and the return pointer of B point to different
283 // fibers. We assume that return pointers never criss-cross, so A must
284 // belong to the child set of A.return, and B must belong to the child
285 // set of B.return.
286 a = parentA;
287 b = parentB;
288 } else {
289 // The return pointers point to the same fiber. We'll have to use the
290 // default, slow path: scan the child sets of each parent alternate to see
291 // which child belongs to which set.
292 //
293 // Search parent A's child set
294 var didFindChild = false;
295 var _child = parentA.child;
296
297 while (_child) {
298 if (_child === a) {
299 didFindChild = true;
300 a = parentA;
301 b = parentB;
302 break;
303 }
304
305 if (_child === b) {
306 didFindChild = true;
307 b = parentA;
308 a = parentB;
309 break;
310 }
311
312 _child = _child.sibling;
313 }
314
315 if (!didFindChild) {
316 // Search parent B's child set
317 _child = parentB.child;
318
319 while (_child) {
320 if (_child === a) {
321 didFindChild = true;
322 a = parentB;
323 b = parentA;
324 break;
325 }
326
327 if (_child === b) {
328 didFindChild = true;
329 b = parentB;
330 a = parentA;
331 break;
332 }
333
334 _child = _child.sibling;
335 }
336
337 if (!didFindChild) {
338 {
339 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." );
340 }
341 }
342 }
343 }
344
345 if (!(a.alternate === b)) {
346 {
347 throw Error( "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue." );
348 }
349 }
350 } // If the root is not a host container, we're in a disconnected tree. I.e.
351 // unmounted.
352
353
354 if (!(a.tag === HostRoot)) {
355 {
356 throw Error( "Unable to find node on an unmounted component." );
357 }
358 }
359
360 if (a.stateNode.current === a) {
361 // We've determined that A is the current branch.
362 return fiber;
363 } // Otherwise B has to be current branch.
364
365
366 return alternate;
367 }
368
369 /**
370 * `charCode` represents the actual "character code" and is safe to use with
371 * `String.fromCharCode`. As such, only keys that correspond to printable
372 * characters produce a valid `charCode`, the only exception to this is Enter.
373 * The Tab-key is considered non-printable and does not have a `charCode`,
374 * presumably because it does not produce a tab-character in browsers.
375 *
376 * @param {object} nativeEvent Native browser event.
377 * @return {number} Normalized `charCode` property.
378 */
379 function getEventCharCode(nativeEvent) {
380 var charCode;
381 var keyCode = nativeEvent.keyCode;
382
383 if ('charCode' in nativeEvent) {
384 charCode = nativeEvent.charCode; // FF does not set `charCode` for the Enter-key, check against `keyCode`.
385
386 if (charCode === 0 && keyCode === 13) {
387 charCode = 13;
388 }
389 } else {
390 // IE8 does not implement `charCode`, but `keyCode` has the correct value.
391 charCode = keyCode;
392 } // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux)
393 // report Enter as charCode 10 when ctrl is pressed.
394
395
396 if (charCode === 10) {
397 charCode = 13;
398 } // Some non-printable keys are reported in `charCode`/`keyCode`, discard them.
399 // Must not discard the (non-)printable Enter-key.
400
401
402 if (charCode >= 32 || charCode === 13) {
403 return charCode;
404 }
405
406 return 0;
407 }
408
409 function functionThatReturnsTrue() {
410 return true;
411 }
412
413 function functionThatReturnsFalse() {
414 return false;
415 } // This is intentionally a factory so that we have different returned constructors.
416 // If we had a single constructor, it would be megamorphic and engines would deopt.
417
418
419 function createSyntheticEvent(Interface) {
420 /**
421 * Synthetic events are dispatched by event plugins, typically in response to a
422 * top-level event delegation handler.
423 *
424 * These systems should generally use pooling to reduce the frequency of garbage
425 * collection. The system should check `isPersistent` to determine whether the
426 * event should be released into the pool after being dispatched. Users that
427 * need a persisted event should invoke `persist`.
428 *
429 * Synthetic events (and subclasses) implement the DOM Level 3 Events API by
430 * normalizing browser quirks. Subclasses do not necessarily have to implement a
431 * DOM interface; custom application-specific events can also subclass this.
432 */
433 function SyntheticBaseEvent(reactName, reactEventType, targetInst, nativeEvent, nativeEventTarget) {
434 this._reactName = reactName;
435 this._targetInst = targetInst;
436 this.type = reactEventType;
437 this.nativeEvent = nativeEvent;
438 this.target = nativeEventTarget;
439 this.currentTarget = null;
440
441 for (var _propName in Interface) {
442 if (!Interface.hasOwnProperty(_propName)) {
443 continue;
444 }
445
446 var normalize = Interface[_propName];
447
448 if (normalize) {
449 this[_propName] = normalize(nativeEvent);
450 } else {
451 this[_propName] = nativeEvent[_propName];
452 }
453 }
454
455 var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false;
456
457 if (defaultPrevented) {
458 this.isDefaultPrevented = functionThatReturnsTrue;
459 } else {
460 this.isDefaultPrevented = functionThatReturnsFalse;
461 }
462
463 this.isPropagationStopped = functionThatReturnsFalse;
464 return this;
465 }
466
467 _assign(SyntheticBaseEvent.prototype, {
468 preventDefault: function () {
469 this.defaultPrevented = true;
470 var event = this.nativeEvent;
471
472 if (!event) {
473 return;
474 }
475
476 if (event.preventDefault) {
477 event.preventDefault(); // $FlowFixMe - flow is not aware of `unknown` in IE
478 } else if (typeof event.returnValue !== 'unknown') {
479 event.returnValue = false;
480 }
481
482 this.isDefaultPrevented = functionThatReturnsTrue;
483 },
484 stopPropagation: function () {
485 var event = this.nativeEvent;
486
487 if (!event) {
488 return;
489 }
490
491 if (event.stopPropagation) {
492 event.stopPropagation(); // $FlowFixMe - flow is not aware of `unknown` in IE
493 } else if (typeof event.cancelBubble !== 'unknown') {
494 // The ChangeEventPlugin registers a "propertychange" event for
495 // IE. This event does not support bubbling or cancelling, and
496 // any references to cancelBubble throw "Member not found". A
497 // typeof check of "unknown" circumvents this issue (and is also
498 // IE specific).
499 event.cancelBubble = true;
500 }
501
502 this.isPropagationStopped = functionThatReturnsTrue;
503 },
504
505 /**
506 * We release all dispatched `SyntheticEvent`s after each event loop, adding
507 * them back into the pool. This allows a way to hold onto a reference that
508 * won't be added back into the pool.
509 */
510 persist: function () {// Modern event system doesn't use pooling.
511 },
512
513 /**
514 * Checks if this event should be released back into the pool.
515 *
516 * @return {boolean} True if this should not be released, false otherwise.
517 */
518 isPersistent: functionThatReturnsTrue
519 });
520
521 return SyntheticBaseEvent;
522 }
523 /**
524 * @interface Event
525 * @see http://www.w3.org/TR/DOM-Level-3-Events/
526 */
527
528
529 var EventInterface = {
530 eventPhase: 0,
531 bubbles: 0,
532 cancelable: 0,
533 timeStamp: function (event) {
534 return event.timeStamp || Date.now();
535 },
536 defaultPrevented: 0,
537 isTrusted: 0
538 };
539 var SyntheticEvent = createSyntheticEvent(EventInterface);
540
541 var UIEventInterface = _assign({}, EventInterface, {
542 view: 0,
543 detail: 0
544 });
545
546 var SyntheticUIEvent = createSyntheticEvent(UIEventInterface);
547 var lastMovementX;
548 var lastMovementY;
549 var lastMouseEvent;
550
551 function updateMouseMovementPolyfillState(event) {
552 if (event !== lastMouseEvent) {
553 if (lastMouseEvent && event.type === 'mousemove') {
554 lastMovementX = event.screenX - lastMouseEvent.screenX;
555 lastMovementY = event.screenY - lastMouseEvent.screenY;
556 } else {
557 lastMovementX = 0;
558 lastMovementY = 0;
559 }
560
561 lastMouseEvent = event;
562 }
563 }
564 /**
565 * @interface MouseEvent
566 * @see http://www.w3.org/TR/DOM-Level-3-Events/
567 */
568
569
570 var MouseEventInterface = _assign({}, UIEventInterface, {
571 screenX: 0,
572 screenY: 0,
573 clientX: 0,
574 clientY: 0,
575 pageX: 0,
576 pageY: 0,
577 ctrlKey: 0,
578 shiftKey: 0,
579 altKey: 0,
580 metaKey: 0,
581 getModifierState: getEventModifierState,
582 button: 0,
583 buttons: 0,
584 relatedTarget: function (event) {
585 if (event.relatedTarget === undefined) return event.fromElement === event.srcElement ? event.toElement : event.fromElement;
586 return event.relatedTarget;
587 },
588 movementX: function (event) {
589 if ('movementX' in event) {
590 return event.movementX;
591 }
592
593 updateMouseMovementPolyfillState(event);
594 return lastMovementX;
595 },
596 movementY: function (event) {
597 if ('movementY' in event) {
598 return event.movementY;
599 } // Don't need to call updateMouseMovementPolyfillState() here
600 // because it's guaranteed to have already run when movementX
601 // was copied.
602
603
604 return lastMovementY;
605 }
606 });
607
608 var SyntheticMouseEvent = createSyntheticEvent(MouseEventInterface);
609 /**
610 * @interface DragEvent
611 * @see http://www.w3.org/TR/DOM-Level-3-Events/
612 */
613
614 var DragEventInterface = _assign({}, MouseEventInterface, {
615 dataTransfer: 0
616 });
617
618 var SyntheticDragEvent = createSyntheticEvent(DragEventInterface);
619 /**
620 * @interface FocusEvent
621 * @see http://www.w3.org/TR/DOM-Level-3-Events/
622 */
623
624 var FocusEventInterface = _assign({}, UIEventInterface, {
625 relatedTarget: 0
626 });
627
628 var SyntheticFocusEvent = createSyntheticEvent(FocusEventInterface);
629 /**
630 * @interface Event
631 * @see http://www.w3.org/TR/css3-animations/#AnimationEvent-interface
632 * @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent
633 */
634
635 var AnimationEventInterface = _assign({}, EventInterface, {
636 animationName: 0,
637 elapsedTime: 0,
638 pseudoElement: 0
639 });
640
641 var SyntheticAnimationEvent = createSyntheticEvent(AnimationEventInterface);
642 /**
643 * @interface Event
644 * @see http://www.w3.org/TR/clipboard-apis/
645 */
646
647 var ClipboardEventInterface = _assign({}, EventInterface, {
648 clipboardData: function (event) {
649 return 'clipboardData' in event ? event.clipboardData : window.clipboardData;
650 }
651 });
652
653 var SyntheticClipboardEvent = createSyntheticEvent(ClipboardEventInterface);
654 /**
655 * @interface Event
656 * @see http://www.w3.org/TR/DOM-Level-3-Events/#events-compositionevents
657 */
658
659 var CompositionEventInterface = _assign({}, EventInterface, {
660 data: 0
661 });
662
663 var SyntheticCompositionEvent = createSyntheticEvent(CompositionEventInterface);
664 /**
665 * Normalization of deprecated HTML5 `key` values
666 * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
667 */
668
669 var normalizeKey = {
670 Esc: 'Escape',
671 Spacebar: ' ',
672 Left: 'ArrowLeft',
673 Up: 'ArrowUp',
674 Right: 'ArrowRight',
675 Down: 'ArrowDown',
676 Del: 'Delete',
677 Win: 'OS',
678 Menu: 'ContextMenu',
679 Apps: 'ContextMenu',
680 Scroll: 'ScrollLock',
681 MozPrintableKey: 'Unidentified'
682 };
683 /**
684 * Translation from legacy `keyCode` to HTML5 `key`
685 * Only special keys supported, all others depend on keyboard layout or browser
686 * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
687 */
688
689 var translateToKey = {
690 '8': 'Backspace',
691 '9': 'Tab',
692 '12': 'Clear',
693 '13': 'Enter',
694 '16': 'Shift',
695 '17': 'Control',
696 '18': 'Alt',
697 '19': 'Pause',
698 '20': 'CapsLock',
699 '27': 'Escape',
700 '32': ' ',
701 '33': 'PageUp',
702 '34': 'PageDown',
703 '35': 'End',
704 '36': 'Home',
705 '37': 'ArrowLeft',
706 '38': 'ArrowUp',
707 '39': 'ArrowRight',
708 '40': 'ArrowDown',
709 '45': 'Insert',
710 '46': 'Delete',
711 '112': 'F1',
712 '113': 'F2',
713 '114': 'F3',
714 '115': 'F4',
715 '116': 'F5',
716 '117': 'F6',
717 '118': 'F7',
718 '119': 'F8',
719 '120': 'F9',
720 '121': 'F10',
721 '122': 'F11',
722 '123': 'F12',
723 '144': 'NumLock',
724 '145': 'ScrollLock',
725 '224': 'Meta'
726 };
727 /**
728 * @param {object} nativeEvent Native browser event.
729 * @return {string} Normalized `key` property.
730 */
731
732 function getEventKey(nativeEvent) {
733 if (nativeEvent.key) {
734 // Normalize inconsistent values reported by browsers due to
735 // implementations of a working draft specification.
736 // FireFox implements `key` but returns `MozPrintableKey` for all
737 // printable characters (normalized to `Unidentified`), ignore it.
738 var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
739
740 if (key !== 'Unidentified') {
741 return key;
742 }
743 } // Browser does not implement `key`, polyfill as much of it as we can.
744
745
746 if (nativeEvent.type === 'keypress') {
747 var charCode = getEventCharCode(nativeEvent); // The enter-key is technically both printable and non-printable and can
748 // thus be captured by `keypress`, no other non-printable key should.
749
750 return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
751 }
752
753 if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
754 // While user keyboard layout determines the actual meaning of each
755 // `keyCode` value, almost all function keys have a universal value.
756 return translateToKey[nativeEvent.keyCode] || 'Unidentified';
757 }
758
759 return '';
760 }
761 /**
762 * Translation from modifier key to the associated property in the event.
763 * @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
764 */
765
766
767 var modifierKeyToProp = {
768 Alt: 'altKey',
769 Control: 'ctrlKey',
770 Meta: 'metaKey',
771 Shift: 'shiftKey'
772 }; // Older browsers (Safari <= 10, iOS Safari <= 10.2) do not support
773 // getModifierState. If getModifierState is not supported, we map it to a set of
774 // modifier keys exposed by the event. In this case, Lock-keys are not supported.
775
776 function modifierStateGetter(keyArg) {
777 var syntheticEvent = this;
778 var nativeEvent = syntheticEvent.nativeEvent;
779
780 if (nativeEvent.getModifierState) {
781 return nativeEvent.getModifierState(keyArg);
782 }
783
784 var keyProp = modifierKeyToProp[keyArg];
785 return keyProp ? !!nativeEvent[keyProp] : false;
786 }
787
788 function getEventModifierState(nativeEvent) {
789 return modifierStateGetter;
790 }
791 /**
792 * @interface KeyboardEvent
793 * @see http://www.w3.org/TR/DOM-Level-3-Events/
794 */
795
796
797 var KeyboardEventInterface = _assign({}, UIEventInterface, {
798 key: getEventKey,
799 code: 0,
800 location: 0,
801 ctrlKey: 0,
802 shiftKey: 0,
803 altKey: 0,
804 metaKey: 0,
805 repeat: 0,
806 locale: 0,
807 getModifierState: getEventModifierState,
808 // Legacy Interface
809 charCode: function (event) {
810 // `charCode` is the result of a KeyPress event and represents the value of
811 // the actual printable character.
812 // KeyPress is deprecated, but its replacement is not yet final and not
813 // implemented in any major browser. Only KeyPress has charCode.
814 if (event.type === 'keypress') {
815 return getEventCharCode(event);
816 }
817
818 return 0;
819 },
820 keyCode: function (event) {
821 // `keyCode` is the result of a KeyDown/Up event and represents the value of
822 // physical keyboard key.
823 // The actual meaning of the value depends on the users' keyboard layout
824 // which cannot be detected. Assuming that it is a US keyboard layout
825 // provides a surprisingly accurate mapping for US and European users.
826 // Due to this, it is left to the user to implement at this time.
827 if (event.type === 'keydown' || event.type === 'keyup') {
828 return event.keyCode;
829 }
830
831 return 0;
832 },
833 which: function (event) {
834 // `which` is an alias for either `keyCode` or `charCode` depending on the
835 // type of the event.
836 if (event.type === 'keypress') {
837 return getEventCharCode(event);
838 }
839
840 if (event.type === 'keydown' || event.type === 'keyup') {
841 return event.keyCode;
842 }
843
844 return 0;
845 }
846 });
847
848 var SyntheticKeyboardEvent = createSyntheticEvent(KeyboardEventInterface);
849 /**
850 * @interface PointerEvent
851 * @see http://www.w3.org/TR/pointerevents/
852 */
853
854 var PointerEventInterface = _assign({}, MouseEventInterface, {
855 pointerId: 0,
856 width: 0,
857 height: 0,
858 pressure: 0,
859 tangentialPressure: 0,
860 tiltX: 0,
861 tiltY: 0,
862 twist: 0,
863 pointerType: 0,
864 isPrimary: 0
865 });
866
867 var SyntheticPointerEvent = createSyntheticEvent(PointerEventInterface);
868 /**
869 * @interface TouchEvent
870 * @see http://www.w3.org/TR/touch-events/
871 */
872
873 var TouchEventInterface = _assign({}, UIEventInterface, {
874 touches: 0,
875 targetTouches: 0,
876 changedTouches: 0,
877 altKey: 0,
878 metaKey: 0,
879 ctrlKey: 0,
880 shiftKey: 0,
881 getModifierState: getEventModifierState
882 });
883
884 var SyntheticTouchEvent = createSyntheticEvent(TouchEventInterface);
885 /**
886 * @interface Event
887 * @see http://www.w3.org/TR/2009/WD-css3-transitions-20090320/#transition-events-
888 * @see https://developer.mozilla.org/en-US/docs/Web/API/TransitionEvent
889 */
890
891 var TransitionEventInterface = _assign({}, EventInterface, {
892 propertyName: 0,
893 elapsedTime: 0,
894 pseudoElement: 0
895 });
896
897 var SyntheticTransitionEvent = createSyntheticEvent(TransitionEventInterface);
898 /**
899 * @interface WheelEvent
900 * @see http://www.w3.org/TR/DOM-Level-3-Events/
901 */
902
903 var WheelEventInterface = _assign({}, MouseEventInterface, {
904 deltaX: function (event) {
905 return 'deltaX' in event ? event.deltaX : // Fallback to `wheelDeltaX` for Webkit and normalize (right is positive).
906 'wheelDeltaX' in event ? -event.wheelDeltaX : 0;
907 },
908 deltaY: function (event) {
909 return 'deltaY' in event ? event.deltaY : // Fallback to `wheelDeltaY` for Webkit and normalize (down is positive).
910 'wheelDeltaY' in event ? -event.wheelDeltaY : // Fallback to `wheelDelta` for IE<9 and normalize (down is positive).
911 'wheelDelta' in event ? -event.wheelDelta : 0;
912 },
913 deltaZ: 0,
914 // Browsers without "deltaMode" is reporting in raw wheel delta where one
915 // notch on the scroll is always +/- 120, roughly equivalent to pixels.
916 // A good approximation of DOM_DELTA_LINE (1) is 5% of viewport size or
917 // ~40 pixels, for DOM_DELTA_SCREEN (2) it is 87.5% of viewport size.
918 deltaMode: 0
919 });
920
921 var SyntheticWheelEvent = createSyntheticEvent(WheelEventInterface);
922
923 /**
924 * HTML nodeType values that represent the type of the node
925 */
926 var ELEMENT_NODE = 1;
927
928 var didWarnAboutMessageChannel = false;
929 var enqueueTaskImpl = null;
930 function enqueueTask(task) {
931 if (enqueueTaskImpl === null) {
932 try {
933 // read require off the module object to get around the bundlers.
934 // we don't want them to detect a require and bundle a Node polyfill.
935 var requireString = ('require' + Math.random()).slice(0, 7);
936 var nodeRequire = module && module[requireString]; // assuming we're in node, let's try to get node's
937 // version of setImmediate, bypassing fake timers if any.
938
939 enqueueTaskImpl = nodeRequire.call(module, 'timers').setImmediate;
940 } catch (_err) {
941 // we're in a browser
942 // we can't use regular timers because they may still be faked
943 // so we try MessageChannel+postMessage instead
944 enqueueTaskImpl = function (callback) {
945 {
946 if (didWarnAboutMessageChannel === false) {
947 didWarnAboutMessageChannel = true;
948
949 if (typeof MessageChannel === 'undefined') {
950 error('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.');
951 }
952 }
953 }
954
955 var channel = new MessageChannel();
956 channel.port1.onmessage = callback;
957 channel.port2.postMessage(undefined);
958 };
959 }
960 }
961
962 return enqueueTaskImpl(task);
963 }
964
965 var ReactInternals$1 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
966 var _ReactInternals$Sched = ReactInternals$1.Scheduler,
967 unstable_cancelCallback = _ReactInternals$Sched.unstable_cancelCallback,
968 unstable_now = _ReactInternals$Sched.unstable_now,
969 unstable_scheduleCallback = _ReactInternals$Sched.unstable_scheduleCallback,
970 unstable_shouldYield = _ReactInternals$Sched.unstable_shouldYield,
971 unstable_requestPaint = _ReactInternals$Sched.unstable_requestPaint,
972 unstable_getFirstCallbackNode = _ReactInternals$Sched.unstable_getFirstCallbackNode,
973 unstable_runWithPriority = _ReactInternals$Sched.unstable_runWithPriority,
974 unstable_next = _ReactInternals$Sched.unstable_next,
975 unstable_continueExecution = _ReactInternals$Sched.unstable_continueExecution,
976 unstable_pauseExecution = _ReactInternals$Sched.unstable_pauseExecution,
977 unstable_getCurrentPriorityLevel = _ReactInternals$Sched.unstable_getCurrentPriorityLevel,
978 unstable_ImmediatePriority = _ReactInternals$Sched.unstable_ImmediatePriority,
979 unstable_UserBlockingPriority = _ReactInternals$Sched.unstable_UserBlockingPriority,
980 unstable_NormalPriority = _ReactInternals$Sched.unstable_NormalPriority,
981 unstable_LowPriority = _ReactInternals$Sched.unstable_LowPriority,
982 unstable_IdlePriority = _ReactInternals$Sched.unstable_IdlePriority,
983 unstable_forceFrameRate = _ReactInternals$Sched.unstable_forceFrameRate,
984 unstable_flushAllWithoutAsserting = _ReactInternals$Sched.unstable_flushAllWithoutAsserting;
985
986 var EventInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events; // const getInstanceFromNode = EventInternals[0];
987 // const getNodeFromInstance = EventInternals[1];
988 // const getFiberCurrentPropsFromNode = EventInternals[2];
989 // const enqueueStateRestore = EventInternals[3];
990 // const restoreStateIfNeeded = EventInternals[4];
991
992 var flushPassiveEffects = EventInternals[5];
993 var IsThisRendererActing = EventInternals[6];
994 var batchedUpdates = ReactDOM.unstable_batchedUpdates;
995 var IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing; // This is the public version of `ReactTestUtils.act`. It is implemented in
996 // "userspace" (i.e. not the reconciler), so that it doesn't add to the
997 // production bundle size.
998 // TODO: Remove this implementation of `act` in favor of the one exported by
999 // the reconciler. To do this, we must first drop support for `act` in
1000 // production mode.
1001 // TODO: Remove support for the mock scheduler build, which was only added for
1002 // the purposes of internal testing. Internal tests should use
1003 // `unstable_concurrentAct` instead.
1004
1005 var isSchedulerMocked = typeof unstable_flushAllWithoutAsserting === 'function';
1006
1007 var flushWork = unstable_flushAllWithoutAsserting || function () {
1008 var didFlushWork = false;
1009
1010 while (flushPassiveEffects()) {
1011 didFlushWork = true;
1012 }
1013
1014 return didFlushWork;
1015 };
1016
1017 function flushWorkAndMicroTasks(onDone) {
1018 try {
1019 flushWork();
1020 enqueueTask(function () {
1021 if (flushWork()) {
1022 flushWorkAndMicroTasks(onDone);
1023 } else {
1024 onDone();
1025 }
1026 });
1027 } catch (err) {
1028 onDone(err);
1029 }
1030 } // we track the 'depth' of the act() calls with this counter,
1031 // so we can tell if any async act() calls try to run in parallel.
1032
1033
1034 var actingUpdatesScopeDepth = 0;
1035 function act(callback) {
1036
1037 var previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
1038 actingUpdatesScopeDepth++;
1039 var previousIsSomeRendererActing = IsSomeRendererActing.current;
1040 var previousIsThisRendererActing = IsThisRendererActing.current;
1041 IsSomeRendererActing.current = true;
1042 IsThisRendererActing.current = true;
1043
1044 function onDone() {
1045 actingUpdatesScopeDepth--;
1046 IsSomeRendererActing.current = previousIsSomeRendererActing;
1047 IsThisRendererActing.current = previousIsThisRendererActing;
1048
1049 {
1050 if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) {
1051 // if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned
1052 error('You seem to have overlapping act() calls, this is not supported. ' + 'Be sure to await previous act() calls before making a new one. ');
1053 }
1054 }
1055 }
1056
1057 var result;
1058
1059 try {
1060 result = batchedUpdates(callback);
1061 } catch (error) {
1062 // on sync errors, we still want to 'cleanup' and decrement actingUpdatesScopeDepth
1063 onDone();
1064 throw error;
1065 }
1066
1067 if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
1068 // setup a boolean that gets set to true only
1069 // once this act() call is await-ed
1070 var called = false;
1071
1072 {
1073 if (typeof Promise !== 'undefined') {
1074 //eslint-disable-next-line no-undef
1075 Promise.resolve().then(function () {}).then(function () {
1076 if (called === false) {
1077 error('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 () => ...);');
1078 }
1079 });
1080 }
1081 } // in the async case, the returned thenable runs the callback, flushes
1082 // effects and microtasks in a loop until flushPassiveEffects() === false,
1083 // and cleans up
1084
1085
1086 return {
1087 then: function (resolve, reject) {
1088 called = true;
1089 result.then(function () {
1090 if (actingUpdatesScopeDepth > 1 || isSchedulerMocked === true && previousIsSomeRendererActing === true) {
1091 onDone();
1092 resolve();
1093 return;
1094 } // we're about to exit the act() scope,
1095 // now's the time to flush tasks/effects
1096
1097
1098 flushWorkAndMicroTasks(function (err) {
1099 onDone();
1100
1101 if (err) {
1102 reject(err);
1103 } else {
1104 resolve();
1105 }
1106 });
1107 }, function (err) {
1108 onDone();
1109 reject(err);
1110 });
1111 }
1112 };
1113 } else {
1114 {
1115 if (result !== undefined) {
1116 error('The callback passed to act(...) function ' + 'must return undefined, or a Promise. You returned %s', result);
1117 }
1118 } // flush effects until none remain, and cleanup
1119
1120
1121 try {
1122 if (actingUpdatesScopeDepth === 1 && (isSchedulerMocked === false || previousIsSomeRendererActing === false)) {
1123 // we're about to exit the act() scope,
1124 // now's the time to flush effects
1125 flushWork();
1126 }
1127
1128 onDone();
1129 } catch (err) {
1130 onDone();
1131 throw err;
1132 } // in the sync case, the returned thenable only warns *if* await-ed
1133
1134
1135 return {
1136 then: function (resolve) {
1137 {
1138 error('Do not await the result of calling act(...) with sync logic, it is not a Promise.');
1139 }
1140
1141 resolve();
1142 }
1143 };
1144 }
1145 }
1146
1147 var EventInternals$1 = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events; // const getInstanceFromNode = EventInternals[0];
1148 // const getNodeFromInstance = EventInternals[1];
1149 // const getFiberCurrentPropsFromNode = EventInternals[2];
1150 // const enqueueStateRestore = EventInternals[3];
1151 // const restoreStateIfNeeded = EventInternals[4];
1152 // const flushPassiveEffects = EventInternals[5];
1153
1154 var IsThisRendererActing$1 = EventInternals$1[6];
1155 var batchedUpdates$1 = ReactDOM.unstable_batchedUpdates;
1156 var IsSomeRendererActing$1 = ReactSharedInternals.IsSomeRendererActing; // This version of `act` is only used by our tests. Unlike the public version
1157 // of `act`, it's designed to work identically in both production and
1158 // development. It may have slightly different behavior from the public
1159 // version, too, since our constraints in our test suite are not the same as
1160 // those of developers using React — we're testing React itself, as opposed to
1161 // building an app with React.
1162
1163 var actingUpdatesScopeDepth$1 = 0;
1164 function unstable_concurrentAct(scope) {
1165 if (unstable_flushAllWithoutAsserting === undefined) {
1166 throw Error('This version of `act` requires a special mock build of Scheduler.');
1167 }
1168
1169 if (setTimeout._isMockFunction !== true) {
1170 throw Error("This version of `act` requires Jest's timer mocks " + '(i.e. jest.useFakeTimers).');
1171 }
1172
1173 var previousActingUpdatesScopeDepth = actingUpdatesScopeDepth$1;
1174 var previousIsSomeRendererActing = IsSomeRendererActing$1.current;
1175 var previousIsThisRendererActing = IsThisRendererActing$1.current;
1176 IsSomeRendererActing$1.current = true;
1177 IsThisRendererActing$1.current = true;
1178 actingUpdatesScopeDepth$1++;
1179
1180 var unwind = function () {
1181 actingUpdatesScopeDepth$1--;
1182 IsSomeRendererActing$1.current = previousIsSomeRendererActing;
1183 IsThisRendererActing$1.current = previousIsThisRendererActing;
1184
1185 {
1186 if (actingUpdatesScopeDepth$1 > previousActingUpdatesScopeDepth) {
1187 // if it's _less than_ previousActingUpdatesScopeDepth, then we can
1188 // assume the 'other' one has warned
1189 error('You seem to have overlapping act() calls, this is not supported. ' + 'Be sure to await previous act() calls before making a new one. ');
1190 }
1191 }
1192 }; // TODO: This would be way simpler if 1) we required a promise to be
1193 // returned and 2) we could use async/await. Since it's only our used in
1194 // our test suite, we should be able to.
1195
1196
1197 try {
1198 var thenable = batchedUpdates$1(scope);
1199
1200 if (typeof thenable === 'object' && thenable !== null && typeof thenable.then === 'function') {
1201 return {
1202 then: function (resolve, reject) {
1203 thenable.then(function () {
1204 flushActWork(function () {
1205 unwind();
1206 resolve();
1207 }, function (error) {
1208 unwind();
1209 reject(error);
1210 });
1211 }, function (error) {
1212 unwind();
1213 reject(error);
1214 });
1215 }
1216 };
1217 } else {
1218 try {
1219 // TODO: Let's not support non-async scopes at all in our tests. Need to
1220 // migrate existing tests.
1221 var didFlushWork;
1222
1223 do {
1224 didFlushWork = unstable_flushAllWithoutAsserting();
1225 } while (didFlushWork);
1226 } finally {
1227 unwind();
1228 }
1229 }
1230 } catch (error) {
1231 unwind();
1232 throw error;
1233 }
1234 }
1235
1236 function flushActWork(resolve, reject) {
1237 // Flush suspended fallbacks
1238 // $FlowFixMe: Flow doesn't know about global Jest object
1239 jest.runOnlyPendingTimers();
1240 enqueueTask(function () {
1241 try {
1242 var didFlushWork = unstable_flushAllWithoutAsserting();
1243
1244 if (didFlushWork) {
1245 flushActWork(resolve, reject);
1246 } else {
1247 resolve();
1248 }
1249 } catch (error) {
1250 reject(error);
1251 }
1252 });
1253 }
1254
1255 function invokeGuardedCallbackProd(name, func, context, a, b, c, d, e, f) {
1256 var funcArgs = Array.prototype.slice.call(arguments, 3);
1257
1258 try {
1259 func.apply(context, funcArgs);
1260 } catch (error) {
1261 this.onError(error);
1262 }
1263 }
1264
1265 var invokeGuardedCallbackImpl = invokeGuardedCallbackProd;
1266
1267 {
1268 // In DEV mode, we swap out invokeGuardedCallback for a special version
1269 // that plays more nicely with the browser's DevTools. The idea is to preserve
1270 // "Pause on exceptions" behavior. Because React wraps all user-provided
1271 // functions in invokeGuardedCallback, and the production version of
1272 // invokeGuardedCallback uses a try-catch, all user exceptions are treated
1273 // like caught exceptions, and the DevTools won't pause unless the developer
1274 // takes the extra step of enabling pause on caught exceptions. This is
1275 // unintuitive, though, because even though React has caught the error, from
1276 // the developer's perspective, the error is uncaught.
1277 //
1278 // To preserve the expected "Pause on exceptions" behavior, we don't use a
1279 // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
1280 // DOM node, and call the user-provided callback from inside an event handler
1281 // for that fake event. If the callback throws, the error is "captured" using
1282 // a global event handler. But because the error happens in a different
1283 // event loop context, it does not interrupt the normal program flow.
1284 // Effectively, this gives us try-catch behavior without actually using
1285 // try-catch. Neat!
1286 // Check that the browser supports the APIs we need to implement our special
1287 // DEV version of invokeGuardedCallback
1288 if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
1289 var fakeNode = document.createElement('react');
1290
1291 invokeGuardedCallbackImpl = function invokeGuardedCallbackDev(name, func, context, a, b, c, d, e, f) {
1292 // If document doesn't exist we know for sure we will crash in this method
1293 // when we call document.createEvent(). However this can cause confusing
1294 // errors: https://github.com/facebookincubator/create-react-app/issues/3482
1295 // So we preemptively throw with a better message instead.
1296 if (!(typeof document !== 'undefined')) {
1297 {
1298 throw 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." );
1299 }
1300 }
1301
1302 var evt = document.createEvent('Event');
1303 var didCall = false; // Keeps track of whether the user-provided callback threw an error. We
1304 // set this to true at the beginning, then set it to false right after
1305 // calling the function. If the function errors, `didError` will never be
1306 // set to false. This strategy works even if the browser is flaky and
1307 // fails to call our global error handler, because it doesn't rely on
1308 // the error event at all.
1309
1310 var didError = true; // Keeps track of the value of window.event so that we can reset it
1311 // during the callback to let user code access window.event in the
1312 // browsers that support it.
1313
1314 var windowEvent = window.event; // Keeps track of the descriptor of window.event to restore it after event
1315 // dispatching: https://github.com/facebook/react/issues/13688
1316
1317 var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event');
1318
1319 function restoreAfterDispatch() {
1320 // We immediately remove the callback from event listeners so that
1321 // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
1322 // nested call would trigger the fake event handlers of any call higher
1323 // in the stack.
1324 fakeNode.removeEventListener(evtType, callCallback, false); // We check for window.hasOwnProperty('event') to prevent the
1325 // window.event assignment in both IE <= 10 as they throw an error
1326 // "Member not found" in strict mode, and in Firefox which does not
1327 // support window.event.
1328
1329 if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
1330 window.event = windowEvent;
1331 }
1332 } // Create an event handler for our fake event. We will synchronously
1333 // dispatch our fake event using `dispatchEvent`. Inside the handler, we
1334 // call the user-provided callback.
1335
1336
1337 var funcArgs = Array.prototype.slice.call(arguments, 3);
1338
1339 function callCallback() {
1340 didCall = true;
1341 restoreAfterDispatch();
1342 func.apply(context, funcArgs);
1343 didError = false;
1344 } // Create a global error event handler. We use this to capture the value
1345 // that was thrown. It's possible that this error handler will fire more
1346 // than once; for example, if non-React code also calls `dispatchEvent`
1347 // and a handler for that event throws. We should be resilient to most of
1348 // those cases. Even if our error event handler fires more than once, the
1349 // last error event is always used. If the callback actually does error,
1350 // we know that the last error event is the correct one, because it's not
1351 // possible for anything else to have happened in between our callback
1352 // erroring and the code that follows the `dispatchEvent` call below. If
1353 // the callback doesn't error, but the error event was fired, we know to
1354 // ignore it because `didError` will be false, as described above.
1355
1356
1357 var error; // Use this to track whether the error event is ever called.
1358
1359 var didSetError = false;
1360 var isCrossOriginError = false;
1361
1362 function handleWindowError(event) {
1363 error = event.error;
1364 didSetError = true;
1365
1366 if (error === null && event.colno === 0 && event.lineno === 0) {
1367 isCrossOriginError = true;
1368 }
1369
1370 if (event.defaultPrevented) {
1371 // Some other error handler has prevented default.
1372 // Browsers silence the error report if this happens.
1373 // We'll remember this to later decide whether to log it or not.
1374 if (error != null && typeof error === 'object') {
1375 try {
1376 error._suppressLogging = true;
1377 } catch (inner) {// Ignore.
1378 }
1379 }
1380 }
1381 } // Create a fake event type.
1382
1383
1384 var evtType = "react-" + (name ? name : 'invokeguardedcallback'); // Attach our event handlers
1385
1386 window.addEventListener('error', handleWindowError);
1387 fakeNode.addEventListener(evtType, callCallback, false); // Synchronously dispatch our fake event. If the user-provided function
1388 // errors, it will trigger our global error handler.
1389
1390 evt.initEvent(evtType, false, false);
1391 fakeNode.dispatchEvent(evt);
1392
1393 if (windowEventDescriptor) {
1394 Object.defineProperty(window, 'event', windowEventDescriptor);
1395 }
1396
1397 if (didCall && didError) {
1398 if (!didSetError) {
1399 // The callback errored, but the error event never fired.
1400 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.');
1401 } else if (isCrossOriginError) {
1402 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.');
1403 }
1404
1405 this.onError(error);
1406 } // Remove our event listeners
1407
1408
1409 window.removeEventListener('error', handleWindowError);
1410
1411 if (!didCall) {
1412 // Something went really wrong, and our event was not dispatched.
1413 // https://github.com/facebook/react/issues/16734
1414 // https://github.com/facebook/react/issues/16585
1415 // Fall back to the production implementation.
1416 restoreAfterDispatch();
1417 return invokeGuardedCallbackProd.apply(this, arguments);
1418 }
1419 };
1420 }
1421 }
1422
1423 var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
1424
1425 var hasError = false;
1426 var caughtError = null; // Used by event system to capture/rethrow the first error.
1427
1428 var hasRethrowError = false;
1429 var rethrowError = null;
1430 var reporter = {
1431 onError: function (error) {
1432 hasError = true;
1433 caughtError = error;
1434 }
1435 };
1436 /**
1437 * Call a function while guarding against errors that happens within it.
1438 * Returns an error if it throws, otherwise null.
1439 *
1440 * In production, this is implemented using a try-catch. The reason we don't
1441 * use a try-catch directly is so that we can swap out a different
1442 * implementation in DEV mode.
1443 *
1444 * @param {String} name of the guard to use for logging or debugging
1445 * @param {Function} func The function to invoke
1446 * @param {*} context The context to use when calling the function
1447 * @param {...*} args Arguments for function
1448 */
1449
1450 function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
1451 hasError = false;
1452 caughtError = null;
1453 invokeGuardedCallbackImpl$1.apply(reporter, arguments);
1454 }
1455 /**
1456 * Same as invokeGuardedCallback, but instead of returning an error, it stores
1457 * it in a global so it can be rethrown by `rethrowCaughtError` later.
1458 * TODO: See if caughtError and rethrowError can be unified.
1459 *
1460 * @param {String} name of the guard to use for logging or debugging
1461 * @param {Function} func The function to invoke
1462 * @param {*} context The context to use when calling the function
1463 * @param {...*} args Arguments for function
1464 */
1465
1466 function invokeGuardedCallbackAndCatchFirstError(name, func, context, a, b, c, d, e, f) {
1467 invokeGuardedCallback.apply(this, arguments);
1468
1469 if (hasError) {
1470 var error = clearCaughtError();
1471
1472 if (!hasRethrowError) {
1473 hasRethrowError = true;
1474 rethrowError = error;
1475 }
1476 }
1477 }
1478 /**
1479 * During execution of guarded functions we will capture the first error which
1480 * we will rethrow to be handled by the top level error handler.
1481 */
1482
1483 function rethrowCaughtError() {
1484 if (hasRethrowError) {
1485 var error = rethrowError;
1486 hasRethrowError = false;
1487 rethrowError = null;
1488 throw error;
1489 }
1490 }
1491 function clearCaughtError() {
1492 if (hasError) {
1493 var error = caughtError;
1494 hasError = false;
1495 caughtError = null;
1496 return error;
1497 } else {
1498 {
1499 {
1500 throw Error( "clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue." );
1501 }
1502 }
1503 }
1504 }
1505
1506 var EventInternals$2 = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events;
1507 var getInstanceFromNode = EventInternals$2[0];
1508 var getNodeFromInstance = EventInternals$2[1];
1509 var getFiberCurrentPropsFromNode = EventInternals$2[2];
1510 var enqueueStateRestore = EventInternals$2[3];
1511 var restoreStateIfNeeded = EventInternals$2[4]; // const flushPassiveEffects = EventInternals[5];
1512 // TODO: This is related to `act`, not events. Move to separate key?
1513 // const IsThisRendererActing = EventInternals[6];
1514
1515 function Event(suffix) {}
1516
1517 var hasWarnedAboutDeprecatedMockComponent = false;
1518 /**
1519 * @class ReactTestUtils
1520 */
1521
1522 function findAllInRenderedFiberTreeInternal(fiber, test) {
1523 if (!fiber) {
1524 return [];
1525 }
1526
1527 var currentParent = findCurrentFiberUsingSlowPath(fiber);
1528
1529 if (!currentParent) {
1530 return [];
1531 }
1532
1533 var node = currentParent;
1534 var ret = [];
1535
1536 while (true) {
1537 if (node.tag === HostComponent || node.tag === HostText || node.tag === ClassComponent || node.tag === FunctionComponent) {
1538 var publicInst = node.stateNode;
1539
1540 if (test(publicInst)) {
1541 ret.push(publicInst);
1542 }
1543 }
1544
1545 if (node.child) {
1546 node.child.return = node;
1547 node = node.child;
1548 continue;
1549 }
1550
1551 if (node === currentParent) {
1552 return ret;
1553 }
1554
1555 while (!node.sibling) {
1556 if (!node.return || node.return === currentParent) {
1557 return ret;
1558 }
1559
1560 node = node.return;
1561 }
1562
1563 node.sibling.return = node.return;
1564 node = node.sibling;
1565 }
1566 }
1567
1568 function validateClassInstance(inst, methodName) {
1569 if (!inst) {
1570 // This is probably too relaxed but it's existing behavior.
1571 return;
1572 }
1573
1574 if (get(inst)) {
1575 // This is a public instance indeed.
1576 return;
1577 }
1578
1579 var received;
1580 var stringified = '' + inst;
1581
1582 if (Array.isArray(inst)) {
1583 received = 'an array';
1584 } else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
1585 received = 'a DOM node';
1586 } else if (stringified === '[object Object]') {
1587 received = 'object with keys {' + Object.keys(inst).join(', ') + '}';
1588 } else {
1589 received = stringified;
1590 }
1591
1592 {
1593 {
1594 throw Error( methodName + "(...): the first argument must be a React class instance. Instead received: " + received + "." );
1595 }
1596 }
1597 }
1598 /**
1599 * Utilities for making it easy to test React components.
1600 *
1601 * See https://reactjs.org/docs/test-utils.html
1602 *
1603 * Todo: Support the entire DOM.scry query syntax. For now, these simple
1604 * utilities will suffice for testing purposes.
1605 * @lends ReactTestUtils
1606 */
1607
1608
1609 function renderIntoDocument(element) {
1610 var div = document.createElement('div'); // None of our tests actually require attaching the container to the
1611 // DOM, and doing so creates a mess that we rely on test isolation to
1612 // clean up, so we're going to stop honoring the name of this method
1613 // (and probably rename it eventually) if no problems arise.
1614 // document.documentElement.appendChild(div);
1615
1616 return ReactDOM.render(element, div);
1617 }
1618
1619 function isElement(element) {
1620 return React.isValidElement(element);
1621 }
1622
1623 function isElementOfType(inst, convenienceConstructor) {
1624 return React.isValidElement(inst) && inst.type === convenienceConstructor;
1625 }
1626
1627 function isDOMComponent(inst) {
1628 return !!(inst && inst.nodeType === ELEMENT_NODE && inst.tagName);
1629 }
1630
1631 function isDOMComponentElement(inst) {
1632 return !!(inst && React.isValidElement(inst) && !!inst.tagName);
1633 }
1634
1635 function isCompositeComponent(inst) {
1636 if (isDOMComponent(inst)) {
1637 // Accessing inst.setState warns; just return false as that'll be what
1638 // this returns when we have DOM nodes as refs directly
1639 return false;
1640 }
1641
1642 return inst != null && typeof inst.render === 'function' && typeof inst.setState === 'function';
1643 }
1644
1645 function isCompositeComponentWithType(inst, type) {
1646 if (!isCompositeComponent(inst)) {
1647 return false;
1648 }
1649
1650 var internalInstance = get(inst);
1651 var constructor = internalInstance.type;
1652 return constructor === type;
1653 }
1654
1655 function findAllInRenderedTree(inst, test) {
1656 validateClassInstance(inst, 'findAllInRenderedTree');
1657
1658 if (!inst) {
1659 return [];
1660 }
1661
1662 var internalInstance = get(inst);
1663 return findAllInRenderedFiberTreeInternal(internalInstance, test);
1664 }
1665 /**
1666 * Finds all instance of components in the rendered tree that are DOM
1667 * components with the class name matching `className`.
1668 * @return {array} an array of all the matches.
1669 */
1670
1671
1672 function scryRenderedDOMComponentsWithClass(root, classNames) {
1673 validateClassInstance(root, 'scryRenderedDOMComponentsWithClass');
1674 return findAllInRenderedTree(root, function (inst) {
1675 if (isDOMComponent(inst)) {
1676 var className = inst.className;
1677
1678 if (typeof className !== 'string') {
1679 // SVG, probably.
1680 className = inst.getAttribute('class') || '';
1681 }
1682
1683 var classList = className.split(/\s+/);
1684
1685 if (!Array.isArray(classNames)) {
1686 if (!(classNames !== undefined)) {
1687 {
1688 throw Error( "TestUtils.scryRenderedDOMComponentsWithClass expects a className as a second argument." );
1689 }
1690 }
1691
1692 classNames = classNames.split(/\s+/);
1693 }
1694
1695 return classNames.every(function (name) {
1696 return classList.indexOf(name) !== -1;
1697 });
1698 }
1699
1700 return false;
1701 });
1702 }
1703 /**
1704 * Like scryRenderedDOMComponentsWithClass but expects there to be one result,
1705 * and returns that one result, or throws exception if there is any other
1706 * number of matches besides one.
1707 * @return {!ReactDOMComponent} The one match.
1708 */
1709
1710
1711 function findRenderedDOMComponentWithClass(root, className) {
1712 validateClassInstance(root, 'findRenderedDOMComponentWithClass');
1713 var all = scryRenderedDOMComponentsWithClass(root, className);
1714
1715 if (all.length !== 1) {
1716 throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for class:' + className);
1717 }
1718
1719 return all[0];
1720 }
1721 /**
1722 * Finds all instance of components in the rendered tree that are DOM
1723 * components with the tag name matching `tagName`.
1724 * @return {array} an array of all the matches.
1725 */
1726
1727
1728 function scryRenderedDOMComponentsWithTag(root, tagName) {
1729 validateClassInstance(root, 'scryRenderedDOMComponentsWithTag');
1730 return findAllInRenderedTree(root, function (inst) {
1731 return isDOMComponent(inst) && inst.tagName.toUpperCase() === tagName.toUpperCase();
1732 });
1733 }
1734 /**
1735 * Like scryRenderedDOMComponentsWithTag but expects there to be one result,
1736 * and returns that one result, or throws exception if there is any other
1737 * number of matches besides one.
1738 * @return {!ReactDOMComponent} The one match.
1739 */
1740
1741
1742 function findRenderedDOMComponentWithTag(root, tagName) {
1743 validateClassInstance(root, 'findRenderedDOMComponentWithTag');
1744 var all = scryRenderedDOMComponentsWithTag(root, tagName);
1745
1746 if (all.length !== 1) {
1747 throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for tag:' + tagName);
1748 }
1749
1750 return all[0];
1751 }
1752 /**
1753 * Finds all instances of components with type equal to `componentType`.
1754 * @return {array} an array of all the matches.
1755 */
1756
1757
1758 function scryRenderedComponentsWithType(root, componentType) {
1759 validateClassInstance(root, 'scryRenderedComponentsWithType');
1760 return findAllInRenderedTree(root, function (inst) {
1761 return isCompositeComponentWithType(inst, componentType);
1762 });
1763 }
1764 /**
1765 * Same as `scryRenderedComponentsWithType` but expects there to be one result
1766 * and returns that one result, or throws exception if there is any other
1767 * number of matches besides one.
1768 * @return {!ReactComponent} The one match.
1769 */
1770
1771
1772 function findRenderedComponentWithType(root, componentType) {
1773 validateClassInstance(root, 'findRenderedComponentWithType');
1774 var all = scryRenderedComponentsWithType(root, componentType);
1775
1776 if (all.length !== 1) {
1777 throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for componentType:' + componentType);
1778 }
1779
1780 return all[0];
1781 }
1782 /**
1783 * Pass a mocked component module to this method to augment it with
1784 * useful methods that allow it to be used as a dummy React component.
1785 * Instead of rendering as usual, the component will become a simple
1786 * <div> containing any provided children.
1787 *
1788 * @param {object} module the mock function object exported from a
1789 * module that defines the component to be mocked
1790 * @param {?string} mockTagName optional dummy root tag name to return
1791 * from render method (overrides
1792 * module.mockTagName if provided)
1793 * @return {object} the ReactTestUtils object (for chaining)
1794 */
1795
1796
1797 function mockComponent(module, mockTagName) {
1798 {
1799 if (!hasWarnedAboutDeprecatedMockComponent) {
1800 hasWarnedAboutDeprecatedMockComponent = true;
1801
1802 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.');
1803 }
1804 }
1805
1806 mockTagName = mockTagName || module.mockTagName || 'div';
1807 module.prototype.render.mockImplementation(function () {
1808 return React.createElement(mockTagName, null, this.props.children);
1809 });
1810 return this;
1811 }
1812
1813 function nativeTouchData(x, y) {
1814 return {
1815 touches: [{
1816 pageX: x,
1817 pageY: y
1818 }]
1819 };
1820 } // Start of inline: the below functions were inlined from
1821 // EventPropagator.js, as they deviated from ReactDOM's newer
1822 // implementations.
1823
1824 /**
1825 * Dispatch the event to the listener.
1826 * @param {SyntheticEvent} event SyntheticEvent to handle
1827 * @param {function} listener Application-level callback
1828 * @param {*} inst Internal component instance
1829 */
1830
1831
1832 function executeDispatch(event, listener, inst) {
1833 var type = event.type || 'unknown-event';
1834 event.currentTarget = getNodeFromInstance(inst);
1835 invokeGuardedCallbackAndCatchFirstError(type, listener, undefined, event);
1836 event.currentTarget = null;
1837 }
1838 /**
1839 * Standard/simple iteration through an event's collected dispatches.
1840 */
1841
1842
1843 function executeDispatchesInOrder(event) {
1844 var dispatchListeners = event._dispatchListeners;
1845 var dispatchInstances = event._dispatchInstances;
1846
1847 if (Array.isArray(dispatchListeners)) {
1848 for (var i = 0; i < dispatchListeners.length; i++) {
1849 if (event.isPropagationStopped()) {
1850 break;
1851 } // Listeners and Instances are two parallel arrays that are always in sync.
1852
1853
1854 executeDispatch(event, dispatchListeners[i], dispatchInstances[i]);
1855 }
1856 } else if (dispatchListeners) {
1857 executeDispatch(event, dispatchListeners, dispatchInstances);
1858 }
1859
1860 event._dispatchListeners = null;
1861 event._dispatchInstances = null;
1862 }
1863 /**
1864 * Dispatches an event and releases it back into the pool, unless persistent.
1865 *
1866 * @param {?object} event Synthetic event to be dispatched.
1867 * @private
1868 */
1869
1870
1871 var executeDispatchesAndRelease = function (event) {
1872 if (event) {
1873 executeDispatchesInOrder(event);
1874
1875 if (!event.isPersistent()) {
1876 event.constructor.release(event);
1877 }
1878 }
1879 };
1880
1881 function isInteractive(tag) {
1882 return tag === 'button' || tag === 'input' || tag === 'select' || tag === 'textarea';
1883 }
1884
1885 function getParent(inst) {
1886 do {
1887 inst = inst.return; // TODO: If this is a HostRoot we might want to bail out.
1888 // That is depending on if we want nested subtrees (layers) to bubble
1889 // events to their parent. We could also go through parentNode on the
1890 // host node but that wouldn't work for React Native and doesn't let us
1891 // do the portal feature.
1892 } while (inst && inst.tag !== HostComponent);
1893
1894 if (inst) {
1895 return inst;
1896 }
1897
1898 return null;
1899 }
1900 /**
1901 * Simulates the traversal of a two-phase, capture/bubble event dispatch.
1902 */
1903
1904
1905 function traverseTwoPhase(inst, fn, arg) {
1906 var path = [];
1907
1908 while (inst) {
1909 path.push(inst);
1910 inst = getParent(inst);
1911 }
1912
1913 var i;
1914
1915 for (i = path.length; i-- > 0;) {
1916 fn(path[i], 'captured', arg);
1917 }
1918
1919 for (i = 0; i < path.length; i++) {
1920 fn(path[i], 'bubbled', arg);
1921 }
1922 }
1923
1924 function shouldPreventMouseEvent(name, type, props) {
1925 switch (name) {
1926 case 'onClick':
1927 case 'onClickCapture':
1928 case 'onDoubleClick':
1929 case 'onDoubleClickCapture':
1930 case 'onMouseDown':
1931 case 'onMouseDownCapture':
1932 case 'onMouseMove':
1933 case 'onMouseMoveCapture':
1934 case 'onMouseUp':
1935 case 'onMouseUpCapture':
1936 case 'onMouseEnter':
1937 return !!(props.disabled && isInteractive(type));
1938
1939 default:
1940 return false;
1941 }
1942 }
1943 /**
1944 * @param {object} inst The instance, which is the source of events.
1945 * @param {string} registrationName Name of listener (e.g. `onClick`).
1946 * @return {?function} The stored callback.
1947 */
1948
1949
1950 function getListener(inst, registrationName) {
1951 // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
1952 // live here; needs to be moved to a better place soon
1953 var stateNode = inst.stateNode;
1954
1955 if (!stateNode) {
1956 // Work in progress (ex: onload events in incremental mode).
1957 return null;
1958 }
1959
1960 var props = getFiberCurrentPropsFromNode(stateNode);
1961
1962 if (!props) {
1963 // Work in progress.
1964 return null;
1965 }
1966
1967 var listener = props[registrationName];
1968
1969 if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
1970 return null;
1971 }
1972
1973 if (!(!listener || typeof listener === 'function')) {
1974 {
1975 throw Error( "Expected `" + registrationName + "` listener to be a function, instead got a value of `" + typeof listener + "` type." );
1976 }
1977 }
1978
1979 return listener;
1980 }
1981
1982 function listenerAtPhase(inst, event, propagationPhase) {
1983 var registrationName = event._reactName;
1984
1985 if (propagationPhase === 'captured') {
1986 registrationName += 'Capture';
1987 }
1988
1989 return getListener(inst, registrationName);
1990 }
1991
1992 function accumulateDispatches(inst, ignoredDirection, event) {
1993 if (inst && event && event._reactName) {
1994 var registrationName = event._reactName;
1995 var listener = getListener(inst, registrationName);
1996
1997 if (listener) {
1998 if (event._dispatchListeners == null) {
1999 event._dispatchListeners = [];
2000 }
2001
2002 if (event._dispatchInstances == null) {
2003 event._dispatchInstances = [];
2004 }
2005
2006 event._dispatchListeners.push(listener);
2007
2008 event._dispatchInstances.push(inst);
2009 }
2010 }
2011 }
2012
2013 function accumulateDirectionalDispatches(inst, phase, event) {
2014 {
2015 if (!inst) {
2016 error('Dispatching inst must not be null');
2017 }
2018 }
2019
2020 var listener = listenerAtPhase(inst, event, phase);
2021
2022 if (listener) {
2023 if (event._dispatchListeners == null) {
2024 event._dispatchListeners = [];
2025 }
2026
2027 if (event._dispatchInstances == null) {
2028 event._dispatchInstances = [];
2029 }
2030
2031 event._dispatchListeners.push(listener);
2032
2033 event._dispatchInstances.push(inst);
2034 }
2035 }
2036
2037 function accumulateDirectDispatchesSingle(event) {
2038 if (event && event._reactName) {
2039 accumulateDispatches(event._targetInst, null, event);
2040 }
2041 }
2042
2043 function accumulateTwoPhaseDispatchesSingle(event) {
2044 if (event && event._reactName) {
2045 traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
2046 }
2047 } // End of inline
2048
2049
2050 var Simulate = {};
2051 var directDispatchEventTypes = new Set(['mouseEnter', 'mouseLeave', 'pointerEnter', 'pointerLeave']);
2052 /**
2053 * Exports:
2054 *
2055 * - `Simulate.click(Element)`
2056 * - `Simulate.mouseMove(Element)`
2057 * - `Simulate.change(Element)`
2058 * - ... (All keys from event plugin `eventTypes` objects)
2059 */
2060
2061 function makeSimulator(eventType) {
2062 return function (domNode, eventData) {
2063 if (!!React.isValidElement(domNode)) {
2064 {
2065 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." );
2066 }
2067 }
2068
2069 if (!!isCompositeComponent(domNode)) {
2070 {
2071 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." );
2072 }
2073 }
2074
2075 var reactName = 'on' + eventType[0].toUpperCase() + eventType.slice(1);
2076 var fakeNativeEvent = new Event();
2077 fakeNativeEvent.target = domNode;
2078 fakeNativeEvent.type = eventType.toLowerCase();
2079 var targetInst = getInstanceFromNode(domNode);
2080 var event = new SyntheticEvent(reactName, fakeNativeEvent.type, targetInst, fakeNativeEvent, domNode); // Since we aren't using pooling, always persist the event. This will make
2081 // sure it's marked and won't warn when setting additional properties.
2082
2083 event.persist();
2084
2085 _assign(event, eventData);
2086
2087 if (directDispatchEventTypes.has(eventType)) {
2088 accumulateDirectDispatchesSingle(event);
2089 } else {
2090 accumulateTwoPhaseDispatchesSingle(event);
2091 }
2092
2093 ReactDOM.unstable_batchedUpdates(function () {
2094 // Normally extractEvent enqueues a state restore, but we'll just always
2095 // do that since we're by-passing it here.
2096 enqueueStateRestore(domNode);
2097 executeDispatchesAndRelease(event);
2098 rethrowCaughtError();
2099 });
2100 restoreStateIfNeeded();
2101 };
2102 } // A one-time snapshot with no plans to update. We'll probably want to deprecate Simulate API.
2103
2104
2105 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', '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'];
2106
2107 function buildSimulators() {
2108 simulatedEventTypes.forEach(function (eventType) {
2109 Simulate[eventType] = makeSimulator(eventType);
2110 });
2111 }
2112
2113 buildSimulators();
2114
2115 exports.Simulate = Simulate;
2116 exports.act = act;
2117 exports.findAllInRenderedTree = findAllInRenderedTree;
2118 exports.findRenderedComponentWithType = findRenderedComponentWithType;
2119 exports.findRenderedDOMComponentWithClass = findRenderedDOMComponentWithClass;
2120 exports.findRenderedDOMComponentWithTag = findRenderedDOMComponentWithTag;
2121 exports.isCompositeComponent = isCompositeComponent;
2122 exports.isCompositeComponentWithType = isCompositeComponentWithType;
2123 exports.isDOMComponent = isDOMComponent;
2124 exports.isDOMComponentElement = isDOMComponentElement;
2125 exports.isElement = isElement;
2126 exports.isElementOfType = isElementOfType;
2127 exports.mockComponent = mockComponent;
2128 exports.nativeTouchData = nativeTouchData;
2129 exports.renderIntoDocument = renderIntoDocument;
2130 exports.scryRenderedComponentsWithType = scryRenderedComponentsWithType;
2131 exports.scryRenderedDOMComponentsWithClass = scryRenderedDOMComponentsWithClass;
2132 exports.scryRenderedDOMComponentsWithTag = scryRenderedDOMComponentsWithTag;
2133 exports.traverseTwoPhase = traverseTwoPhase;
2134 exports.unstable_concurrentAct = unstable_concurrentAct;
2135
2136})));