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