1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
8 |
|
9 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
10 |
|
11 | var _object = require('object.assign');
|
12 |
|
13 | var _object2 = _interopRequireDefault(_object);
|
14 |
|
15 | var _cheerio = require('cheerio');
|
16 |
|
17 | var _cheerio2 = _interopRequireDefault(_cheerio);
|
18 |
|
19 | var _arrayPrototype = require('array.prototype.flat');
|
20 |
|
21 | var _arrayPrototype2 = _interopRequireDefault(_arrayPrototype);
|
22 |
|
23 | var _Utils = require('./Utils');
|
24 |
|
25 | var _getAdapter = require('./getAdapter');
|
26 |
|
27 | var _getAdapter2 = _interopRequireDefault(_getAdapter);
|
28 |
|
29 | var _Debug = require('./Debug');
|
30 |
|
31 | var _RSTTraversal = require('./RSTTraversal');
|
32 |
|
33 | var _selectors = require('./selectors');
|
34 |
|
35 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
36 |
|
37 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
38 |
|
39 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
40 |
|
41 | var NODE = (0, _Utils.sym)('__node__');
|
42 | var NODES = (0, _Utils.sym)('__nodes__');
|
43 | var RENDERER = (0, _Utils.sym)('__renderer__');
|
44 | var UNRENDERED = (0, _Utils.sym)('__unrendered__');
|
45 | var ROOT = (0, _Utils.sym)('__root__');
|
46 | var OPTIONS = (0, _Utils.sym)('__options__');
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | function findWhereUnwrapped(wrapper, predicate) {
|
58 | var filter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _RSTTraversal.treeFilter;
|
59 |
|
60 | return wrapper.flatMap(function (n) {
|
61 | return filter(n.getNodeInternal(), predicate);
|
62 | });
|
63 | }
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | function filterWhereUnwrapped(wrapper, predicate) {
|
74 | return wrapper.wrap(wrapper.getNodesInternal().filter(predicate).filter(Boolean));
|
75 | }
|
76 |
|
77 | function nodeParents(wrapper, node) {
|
78 | return (0, _RSTTraversal.parentsOfNode)(node, wrapper[ROOT].getNodeInternal());
|
79 | }
|
80 |
|
81 | function privateSetNodes(wrapper, nodes) {
|
82 | if (!nodes) {
|
83 | (0, _Utils.privateSet)(wrapper, NODE, null);
|
84 | (0, _Utils.privateSet)(wrapper, NODES, []);
|
85 | } else if (!Array.isArray(nodes)) {
|
86 | (0, _Utils.privateSet)(wrapper, NODE, nodes);
|
87 | (0, _Utils.privateSet)(wrapper, NODES, [nodes]);
|
88 | } else {
|
89 | (0, _Utils.privateSet)(wrapper, NODE, nodes[0]);
|
90 | (0, _Utils.privateSet)(wrapper, NODES, nodes);
|
91 | }
|
92 | (0, _Utils.privateSet)(wrapper, 'length', wrapper[NODES].length);
|
93 | }
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | var ReactWrapper = function () {
|
100 | function ReactWrapper(nodes, root) {
|
101 | var passedOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
102 |
|
103 | _classCallCheck(this, ReactWrapper);
|
104 |
|
105 | if (!global.window && !global.document) {
|
106 | throw new Error('It looks like you called `mount()` without a global document being loaded.');
|
107 | }
|
108 | var options = (0, _Utils.makeOptions)(passedOptions);
|
109 |
|
110 | if (!root) {
|
111 | var adapter = (0, _getAdapter2['default'])(options);
|
112 | if (!adapter.isValidElement(nodes)) {
|
113 | throw new TypeError('ReactWrapper can only wrap valid elements');
|
114 | }
|
115 |
|
116 | (0, _Utils.privateSet)(this, UNRENDERED, nodes);
|
117 | var renderer = adapter.createRenderer((0, _object2['default'])({ mode: 'mount' }, options));
|
118 | (0, _Utils.privateSet)(this, RENDERER, renderer);
|
119 | renderer.render(nodes, options.context);
|
120 | (0, _Utils.privateSet)(this, ROOT, this);
|
121 | privateSetNodes(this, this[RENDERER].getNode());
|
122 | } else {
|
123 | (0, _Utils.privateSet)(this, UNRENDERED, null);
|
124 | (0, _Utils.privateSet)(this, RENDERER, root[RENDERER]);
|
125 | (0, _Utils.privateSet)(this, ROOT, root);
|
126 | privateSetNodes(this, nodes);
|
127 | }
|
128 | (0, _Utils.privateSet)(this, OPTIONS, root ? root[OPTIONS] : options);
|
129 | }
|
130 |
|
131 | |
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | _createClass(ReactWrapper, [{
|
139 | key: 'root',
|
140 | value: function () {
|
141 | function root() {
|
142 | return this[ROOT];
|
143 | }
|
144 |
|
145 | return root;
|
146 | }()
|
147 |
|
148 | |
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 | }, {
|
155 | key: 'getNodeInternal',
|
156 | value: function () {
|
157 | function getNodeInternal() {
|
158 | if (this.length !== 1) {
|
159 | throw new Error('ReactWrapper::getNode() can only be called when wrapping one node');
|
160 | }
|
161 | return this[NODES][0];
|
162 | }
|
163 |
|
164 | return getNodeInternal;
|
165 | }()
|
166 |
|
167 | |
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 | }, {
|
174 | key: 'getNodesInternal',
|
175 | value: function () {
|
176 | function getNodesInternal() {
|
177 | return this[NODES];
|
178 | }
|
179 |
|
180 | return getNodesInternal;
|
181 | }()
|
182 |
|
183 | |
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 | }, {
|
190 | key: 'getElement',
|
191 | value: function () {
|
192 | function getElement() {
|
193 | if (this.length !== 1) {
|
194 | throw new Error('ReactWrapper::getElement() can only be called when wrapping one node');
|
195 | }
|
196 | return (0, _getAdapter2['default'])(this[OPTIONS]).nodeToElement(this[NODE]);
|
197 | }
|
198 |
|
199 | return getElement;
|
200 | }()
|
201 |
|
202 | |
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 | }, {
|
209 | key: 'getElements',
|
210 | value: function () {
|
211 | function getElements() {
|
212 | return this[NODES].map((0, _getAdapter2['default'])(this[OPTIONS]).nodeToElement);
|
213 | }
|
214 |
|
215 | return getElements;
|
216 | }()
|
217 |
|
218 |
|
219 |
|
220 | }, {
|
221 | key: 'getNode',
|
222 | value: function () {
|
223 | function getNode() {
|
224 | throw new Error('ReactWrapper::getNode() is no longer supported. Use ReactWrapper::instance() instead');
|
225 | }
|
226 |
|
227 | return getNode;
|
228 | }()
|
229 |
|
230 |
|
231 |
|
232 | }, {
|
233 | key: 'getNodes',
|
234 | value: function () {
|
235 | function getNodes() {
|
236 | throw new Error('ReactWrapper::getNodes() is no longer supported.');
|
237 | }
|
238 |
|
239 | return getNodes;
|
240 | }()
|
241 |
|
242 | |
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 | }, {
|
251 | key: 'getDOMNode',
|
252 | value: function () {
|
253 | function getDOMNode() {
|
254 | var adapter = (0, _getAdapter2['default'])(this[OPTIONS]);
|
255 | return this.single('getDOMNode', function (n) {
|
256 | return adapter.nodeToHostNode(n);
|
257 | });
|
258 | }
|
259 |
|
260 | return getDOMNode;
|
261 | }()
|
262 |
|
263 | |
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 | }, {
|
274 | key: 'ref',
|
275 | value: function () {
|
276 | function ref(refname) {
|
277 | if (this[ROOT] !== this) {
|
278 | throw new Error('ReactWrapper::ref(refname) can only be called on the root');
|
279 | }
|
280 | return this.instance().refs[refname];
|
281 | }
|
282 |
|
283 | return ref;
|
284 | }()
|
285 |
|
286 | |
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 | }, {
|
299 | key: 'instance',
|
300 | value: function () {
|
301 | function instance() {
|
302 | if (this.length !== 1) {
|
303 | throw new Error('ReactWrapper::instance() can only be called on single nodes');
|
304 | }
|
305 | return this[NODE].instance;
|
306 | }
|
307 |
|
308 | return instance;
|
309 | }()
|
310 |
|
311 | |
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 | }, {
|
321 | key: 'update',
|
322 | value: function () {
|
323 | function update() {
|
324 | if (this[ROOT] !== this) {
|
325 | throw new Error('ReactWrapper::update() can only be called on the root');
|
326 | }
|
327 | privateSetNodes(this, this[RENDERER].getNode());
|
328 | return this;
|
329 | }
|
330 |
|
331 | return update;
|
332 | }()
|
333 |
|
334 | |
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 | }, {
|
342 | key: 'unmount',
|
343 | value: function () {
|
344 | function unmount() {
|
345 | var _this = this;
|
346 |
|
347 | if (this[ROOT] !== this) {
|
348 | throw new Error('ReactWrapper::unmount() can only be called on the root');
|
349 | }
|
350 | this.single('unmount', function () {
|
351 | _this[RENDERER].unmount();
|
352 | _this.update();
|
353 | });
|
354 | return this;
|
355 | }
|
356 |
|
357 | return unmount;
|
358 | }()
|
359 |
|
360 | |
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 | }, {
|
369 | key: 'mount',
|
370 | value: function () {
|
371 | function mount() {
|
372 | var _this2 = this;
|
373 |
|
374 | if (this[ROOT] !== this) {
|
375 | throw new Error('ReactWrapper::mount() can only be called on the root');
|
376 | }
|
377 | this[RENDERER].render(this[UNRENDERED], this[OPTIONS].context, function () {
|
378 | return _this2.update();
|
379 | });
|
380 | return this;
|
381 | }
|
382 |
|
383 | return mount;
|
384 | }()
|
385 |
|
386 | |
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 | }, {
|
402 | key: 'setProps',
|
403 | value: function () {
|
404 | function setProps(props) {
|
405 | var _this3 = this;
|
406 |
|
407 | var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
408 |
|
409 | if (this[ROOT] !== this) {
|
410 | throw new Error('ReactWrapper::setProps() can only be called on the root');
|
411 | }
|
412 | if (arguments.length > 1 && typeof callback !== 'function') {
|
413 | throw new TypeError('ReactWrapper::setProps() expects a function as its second argument');
|
414 | }
|
415 | var adapter = (0, _getAdapter2['default'])(this[OPTIONS]);
|
416 | this[UNRENDERED] = (0, _Utils.cloneElement)(adapter, this[UNRENDERED], props);
|
417 | this[RENDERER].render(this[UNRENDERED], null, function () {
|
418 | _this3.update();
|
419 | if (callback) {
|
420 | callback();
|
421 | }
|
422 | });
|
423 | return this;
|
424 | }
|
425 |
|
426 | return setProps;
|
427 | }()
|
428 |
|
429 | |
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 | }, {
|
444 | key: 'setState',
|
445 | value: function () {
|
446 | function setState(state) {
|
447 | var _this4 = this;
|
448 |
|
449 | var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
450 |
|
451 | if (this[ROOT] !== this) {
|
452 | throw new Error('ReactWrapper::setState() can only be called on the root');
|
453 | }
|
454 | if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') {
|
455 | throw new Error('ReactWrapper::setState() can only be called on class components');
|
456 | }
|
457 | if (arguments.length > 1 && typeof callback !== 'function') {
|
458 | throw new TypeError('ReactWrapper::setState() expects a function as its second argument');
|
459 | }
|
460 | this.instance().setState(state, function () {
|
461 | _this4.update();
|
462 | if (callback) {
|
463 | var adapter = (0, _getAdapter2['default'])(_this4[OPTIONS]);
|
464 | var instance = _this4.instance();
|
465 | if (adapter.invokeSetStateCallback) {
|
466 | adapter.invokeSetStateCallback(instance, callback);
|
467 | } else {
|
468 | callback.call(instance);
|
469 | }
|
470 | }
|
471 | });
|
472 | return this;
|
473 | }
|
474 |
|
475 | return setState;
|
476 | }()
|
477 |
|
478 | |
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 | }, {
|
489 | key: 'setContext',
|
490 | value: function () {
|
491 | function setContext(context) {
|
492 | var _this5 = this;
|
493 |
|
494 | if (this[ROOT] !== this) {
|
495 | throw new Error('ReactWrapper::setContext() can only be called on the root');
|
496 | }
|
497 | if (!this[OPTIONS].context) {
|
498 | throw new Error('ShallowWrapper::setContext() can only be called on a wrapper that was originally passed a context option');
|
499 | }
|
500 | this[RENDERER].render(this[UNRENDERED], context, function () {
|
501 | return _this5.update();
|
502 | });
|
503 | return this;
|
504 | }
|
505 |
|
506 | return setContext;
|
507 | }()
|
508 |
|
509 | |
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 | }, {
|
523 | key: 'contains',
|
524 | value: function () {
|
525 | function contains(nodeOrNodes) {
|
526 | var adapter = (0, _getAdapter2['default'])(this[OPTIONS]);
|
527 |
|
528 | var predicate = Array.isArray(nodeOrNodes) ? function (other) {
|
529 | return (0, _Utils.containsChildrenSubArray)(_Utils.nodeEqual, other, nodeOrNodes.map(function (node) {
|
530 | return adapter.elementToNode(node);
|
531 | }));
|
532 | } : function (other) {
|
533 | return (0, _Utils.nodeEqual)(adapter.elementToNode(nodeOrNodes), other);
|
534 | };
|
535 |
|
536 | return findWhereUnwrapped(this, predicate).length > 0;
|
537 | }
|
538 |
|
539 | return contains;
|
540 | }()
|
541 |
|
542 | |
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 | }, {
|
560 | key: 'containsMatchingElement',
|
561 | value: function () {
|
562 | function containsMatchingElement(node) {
|
563 | var rstNode = (0, _getAdapter2['default'])(this[OPTIONS]).elementToNode(node);
|
564 | var predicate = function () {
|
565 | function predicate(other) {
|
566 | return (0, _Utils.nodeMatches)(rstNode, other, function (a, b) {
|
567 | return a <= b;
|
568 | });
|
569 | }
|
570 |
|
571 | return predicate;
|
572 | }();
|
573 | return findWhereUnwrapped(this, predicate).length > 0;
|
574 | }
|
575 |
|
576 | return containsMatchingElement;
|
577 | }()
|
578 |
|
579 | |
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 | }, {
|
599 | key: 'containsAllMatchingElements',
|
600 | value: function () {
|
601 | function containsAllMatchingElements(nodes) {
|
602 | var _this6 = this;
|
603 |
|
604 | if (!Array.isArray(nodes)) {
|
605 | throw new TypeError('nodes should be an Array');
|
606 | }
|
607 |
|
608 | return nodes.every(function (node) {
|
609 | return _this6.containsMatchingElement(node);
|
610 | });
|
611 | }
|
612 |
|
613 | return containsAllMatchingElements;
|
614 | }()
|
615 |
|
616 | |
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 | }, {
|
636 | key: 'containsAnyMatchingElements',
|
637 | value: function () {
|
638 | function containsAnyMatchingElements(nodes) {
|
639 | var _this7 = this;
|
640 |
|
641 | return Array.isArray(nodes) && nodes.some(function (node) {
|
642 | return _this7.containsMatchingElement(node);
|
643 | });
|
644 | }
|
645 |
|
646 | return containsAnyMatchingElements;
|
647 | }()
|
648 |
|
649 | |
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 | }, {
|
663 | key: 'equals',
|
664 | value: function () {
|
665 | function equals(node) {
|
666 | var _this8 = this;
|
667 |
|
668 | return this.single('equals', function () {
|
669 | return (0, _Utils.nodeEqual)(_this8.getNodeInternal(), node);
|
670 | });
|
671 | }
|
672 |
|
673 | return equals;
|
674 | }()
|
675 |
|
676 | |
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 | }, {
|
695 | key: 'matchesElement',
|
696 | value: function () {
|
697 | function matchesElement(node) {
|
698 | var _this9 = this;
|
699 |
|
700 | return this.single('matchesElement', function () {
|
701 | var adapter = (0, _getAdapter2['default'])(_this9[OPTIONS]);
|
702 | var rstNode = adapter.elementToNode(node);
|
703 | return (0, _Utils.nodeMatches)(rstNode, _this9.getNodeInternal(), function (a, b) {
|
704 | return a <= b;
|
705 | });
|
706 | });
|
707 | }
|
708 |
|
709 | return matchesElement;
|
710 | }()
|
711 |
|
712 | |
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 | }, {
|
720 | key: 'find',
|
721 | value: function () {
|
722 | function find(selector) {
|
723 | return this.wrap((0, _selectors.reduceTreesBySelector)(selector, this.getNodesInternal()));
|
724 | }
|
725 |
|
726 | return find;
|
727 | }()
|
728 |
|
729 | |
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 | }, {
|
739 | key: 'is',
|
740 | value: function () {
|
741 | function is(selector) {
|
742 | var predicate = (0, _selectors.buildPredicate)(selector);
|
743 | return this.single('is', function (n) {
|
744 | return predicate(n);
|
745 | });
|
746 | }
|
747 |
|
748 | return is;
|
749 | }()
|
750 |
|
751 | |
752 |
|
753 |
|
754 |
|
755 |
|
756 |
|
757 | }, {
|
758 | key: 'isEmptyRender',
|
759 | value: function () {
|
760 | function isEmptyRender() {
|
761 | return this.single('isEmptyRender', function (n) {
|
762 | return n.rendered === null;
|
763 | });
|
764 | }
|
765 |
|
766 | return isEmptyRender;
|
767 | }()
|
768 |
|
769 | |
770 |
|
771 |
|
772 |
|
773 |
|
774 |
|
775 |
|
776 |
|
777 | }, {
|
778 | key: 'filterWhere',
|
779 | value: function () {
|
780 | function filterWhere(predicate) {
|
781 | var _this10 = this;
|
782 |
|
783 | return filterWhereUnwrapped(this, function (n) {
|
784 | return predicate(_this10.wrap(n));
|
785 | });
|
786 | }
|
787 |
|
788 | return filterWhere;
|
789 | }()
|
790 |
|
791 | |
792 |
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 |
|
799 | }, {
|
800 | key: 'filter',
|
801 | value: function () {
|
802 | function filter(selector) {
|
803 | var predicate = (0, _selectors.buildPredicate)(selector);
|
804 | return filterWhereUnwrapped(this, predicate);
|
805 | }
|
806 |
|
807 | return filter;
|
808 | }()
|
809 |
|
810 | |
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 | }, {
|
819 | key: 'not',
|
820 | value: function () {
|
821 | function not(selector) {
|
822 | var predicate = (0, _selectors.buildPredicate)(selector);
|
823 | return filterWhereUnwrapped(this, function (n) {
|
824 | return !predicate(n);
|
825 | });
|
826 | }
|
827 |
|
828 | return not;
|
829 | }()
|
830 |
|
831 | |
832 |
|
833 |
|
834 |
|
835 |
|
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 | }, {
|
842 | key: 'text',
|
843 | value: function () {
|
844 | function text() {
|
845 | var adapter = (0, _getAdapter2['default'])(this[OPTIONS]);
|
846 | return this.single('text', function (n) {
|
847 | var node = adapter.nodeToHostNode(n);
|
848 | return node && node.textContent;
|
849 | });
|
850 | }
|
851 |
|
852 | return text;
|
853 | }()
|
854 |
|
855 | |
856 |
|
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 | }, {
|
864 | key: 'html',
|
865 | value: function () {
|
866 | function html() {
|
867 | var _this11 = this;
|
868 |
|
869 | return this.single('html', function (n) {
|
870 | if (n === null) return null;
|
871 | var adapter = (0, _getAdapter2['default'])(_this11[OPTIONS]);
|
872 | var node = adapter.nodeToHostNode(n);
|
873 | return node === null ? null : node.outerHTML.replace(/\sdata-(reactid|reactroot)+="([^"]*)+"/g, '');
|
874 | });
|
875 | }
|
876 |
|
877 | return html;
|
878 | }()
|
879 |
|
880 | |
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 | }, {
|
889 | key: 'render',
|
890 | value: function () {
|
891 | function render() {
|
892 | var html = this.html();
|
893 | return html === null ? (0, _cheerio2['default'])() : _cheerio2['default'].load('')(html);
|
894 | }
|
895 |
|
896 | return render;
|
897 | }()
|
898 |
|
899 | |
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 |
|
908 | }, {
|
909 | key: 'simulate',
|
910 | value: function () {
|
911 | function simulate(event) {
|
912 | var _this12 = this;
|
913 |
|
914 | var mock = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
915 |
|
916 | return this.single('simulate', function (n) {
|
917 | _this12[RENDERER].simulateEvent(n, event, mock);
|
918 | _this12[ROOT].update();
|
919 | return _this12;
|
920 | });
|
921 | }
|
922 |
|
923 | return simulate;
|
924 | }()
|
925 |
|
926 | |
927 |
|
928 |
|
929 |
|
930 |
|
931 |
|
932 |
|
933 | }, {
|
934 | key: 'simulateError',
|
935 | value: function () {
|
936 | function simulateError(error) {
|
937 | var _this13 = this;
|
938 |
|
939 | if (this[ROOT] === this) {
|
940 | throw new Error('ReactWrapper::simulateError() may not be called on the root');
|
941 | }
|
942 |
|
943 | return this.single('simulateError', function (thisNode) {
|
944 | if (thisNode.nodeType === 'host') {
|
945 | throw new Error('ReactWrapper::simulateError() can only be called on custom components');
|
946 | }
|
947 |
|
948 | var renderer = _this13[RENDERER];
|
949 | if (typeof renderer.simulateError !== 'function') {
|
950 | throw new TypeError('your adapter does not support `simulateError`. Try upgrading it!');
|
951 | }
|
952 |
|
953 | var rootNode = _this13[ROOT].getNodeInternal();
|
954 | var nodeHierarchy = [thisNode].concat(nodeParents(_this13, thisNode));
|
955 | renderer.simulateError(nodeHierarchy, rootNode, error);
|
956 |
|
957 | return _this13;
|
958 | });
|
959 | }
|
960 |
|
961 | return simulateError;
|
962 | }()
|
963 |
|
964 | |
965 |
|
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 |
|
972 | }, {
|
973 | key: 'props',
|
974 | value: function () {
|
975 | function props() {
|
976 | return this.single('props', _RSTTraversal.propsOfNode);
|
977 | }
|
978 |
|
979 | return props;
|
980 | }()
|
981 |
|
982 | |
983 |
|
984 |
|
985 |
|
986 |
|
987 |
|
988 |
|
989 |
|
990 |
|
991 |
|
992 | }, {
|
993 | key: 'state',
|
994 | value: function () {
|
995 | function state(name) {
|
996 | var _this14 = this;
|
997 |
|
998 | if (this[ROOT] !== this) {
|
999 | throw new Error('ReactWrapper::state() can only be called on the root');
|
1000 | }
|
1001 | if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') {
|
1002 | throw new Error('ReactWrapper::state() can only be called on class components');
|
1003 | }
|
1004 | var _state = this.single('state', function () {
|
1005 | return _this14.instance().state;
|
1006 | });
|
1007 | if (typeof name !== 'undefined') {
|
1008 | return _state[name];
|
1009 | }
|
1010 | return _state;
|
1011 | }
|
1012 |
|
1013 | return state;
|
1014 | }()
|
1015 |
|
1016 | |
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 | }, {
|
1027 | key: 'context',
|
1028 | value: function () {
|
1029 | function context(name) {
|
1030 | var _this15 = this;
|
1031 |
|
1032 | if (this[ROOT] !== this) {
|
1033 | throw new Error('ReactWrapper::context() can only be called on the root');
|
1034 | }
|
1035 | var instance = this.single('context', function () {
|
1036 | return _this15.instance();
|
1037 | });
|
1038 | if (instance === null) {
|
1039 | throw new Error('ReactWrapper::context() can only be called on components with instances');
|
1040 | }
|
1041 | var _context = instance.context;
|
1042 | if (typeof name !== 'undefined') {
|
1043 | return _context[name];
|
1044 | }
|
1045 | return _context;
|
1046 | }
|
1047 |
|
1048 | return context;
|
1049 | }()
|
1050 |
|
1051 | |
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 | }, {
|
1059 | key: 'children',
|
1060 | value: function () {
|
1061 | function children(selector) {
|
1062 | var allChildren = this.flatMap(function (n) {
|
1063 | return (0, _RSTTraversal.childrenOfNode)(n.getNodeInternal()).filter(function (x) {
|
1064 | return (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object';
|
1065 | });
|
1066 | });
|
1067 | return selector ? allChildren.filter(selector) : allChildren;
|
1068 | }
|
1069 |
|
1070 | return children;
|
1071 | }()
|
1072 |
|
1073 | |
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 | }, {
|
1081 | key: 'childAt',
|
1082 | value: function () {
|
1083 | function childAt(index) {
|
1084 | var _this16 = this;
|
1085 |
|
1086 | return this.single('childAt', function () {
|
1087 | return _this16.children().at(index);
|
1088 | });
|
1089 | }
|
1090 |
|
1091 | return childAt;
|
1092 | }()
|
1093 |
|
1094 | |
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 | }, {
|
1105 | key: 'parents',
|
1106 | value: function () {
|
1107 | function parents(selector) {
|
1108 | var _this17 = this;
|
1109 |
|
1110 | var allParents = this.wrap(this.single('parents', function (n) {
|
1111 | return nodeParents(_this17, n);
|
1112 | }));
|
1113 | return selector ? allParents.filter(selector) : allParents;
|
1114 | }
|
1115 |
|
1116 | return parents;
|
1117 | }()
|
1118 |
|
1119 | |
1120 |
|
1121 |
|
1122 |
|
1123 |
|
1124 |
|
1125 | }, {
|
1126 | key: 'parent',
|
1127 | value: function () {
|
1128 | function parent() {
|
1129 | return this.flatMap(function (n) {
|
1130 | return [n.parents().get(0)];
|
1131 | });
|
1132 | }
|
1133 |
|
1134 | return parent;
|
1135 | }()
|
1136 |
|
1137 | |
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 |
|
1143 | }, {
|
1144 | key: 'closest',
|
1145 | value: function () {
|
1146 | function closest(selector) {
|
1147 | if (this.is(selector)) {
|
1148 | return this;
|
1149 | }
|
1150 | var matchingAncestors = this.parents().filter(selector);
|
1151 | return matchingAncestors.length > 0 ? matchingAncestors.first() : this.findWhere(function () {
|
1152 | return false;
|
1153 | });
|
1154 | }
|
1155 |
|
1156 | return closest;
|
1157 | }()
|
1158 |
|
1159 | |
1160 |
|
1161 |
|
1162 |
|
1163 |
|
1164 |
|
1165 |
|
1166 | }, {
|
1167 | key: 'prop',
|
1168 | value: function () {
|
1169 | function prop(propName) {
|
1170 | return this.props()[propName];
|
1171 | }
|
1172 |
|
1173 | return prop;
|
1174 | }()
|
1175 |
|
1176 | |
1177 |
|
1178 |
|
1179 |
|
1180 |
|
1181 |
|
1182 | }, {
|
1183 | key: 'key',
|
1184 | value: function () {
|
1185 | function key() {
|
1186 | return this.single('key', function (n) {
|
1187 | return n.key === undefined ? null : n.key;
|
1188 | });
|
1189 | }
|
1190 |
|
1191 | return key;
|
1192 | }()
|
1193 |
|
1194 | |
1195 |
|
1196 |
|
1197 |
|
1198 |
|
1199 |
|
1200 |
|
1201 | }, {
|
1202 | key: 'type',
|
1203 | value: function () {
|
1204 | function type() {
|
1205 | return this.single('type', function (n) {
|
1206 | return (0, _Utils.typeOfNode)(n);
|
1207 | });
|
1208 | }
|
1209 |
|
1210 | return type;
|
1211 | }()
|
1212 |
|
1213 | |
1214 |
|
1215 |
|
1216 |
|
1217 |
|
1218 |
|
1219 |
|
1220 |
|
1221 | }, {
|
1222 | key: 'name',
|
1223 | value: function () {
|
1224 | function name() {
|
1225 | var adapter = (0, _getAdapter2['default'])(this[OPTIONS]);
|
1226 | return this.single('name', function (n) {
|
1227 | return adapter.displayNameOfNode ? adapter.displayNameOfNode(n) : (0, _Utils.displayNameOfNode)(n);
|
1228 | });
|
1229 | }
|
1230 |
|
1231 | return name;
|
1232 | }()
|
1233 |
|
1234 | |
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 |
|
1241 |
|
1242 |
|
1243 | }, {
|
1244 | key: 'hasClass',
|
1245 | value: function () {
|
1246 | function hasClass(className) {
|
1247 | if (className && className.indexOf('.') !== -1) {
|
1248 |
|
1249 | console.warn('It looks like you\'re calling `ReactWrapper::hasClass()` with a CSS selector. hasClass() expects a class name, not a CSS selector.');
|
1250 | }
|
1251 | return this.single('hasClass', function (n) {
|
1252 | return (0, _RSTTraversal.hasClassName)(n, className);
|
1253 | });
|
1254 | }
|
1255 |
|
1256 | return hasClass;
|
1257 | }()
|
1258 |
|
1259 | |
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 | }, {
|
1268 | key: 'forEach',
|
1269 | value: function () {
|
1270 | function forEach(fn) {
|
1271 | var _this18 = this;
|
1272 |
|
1273 | this.getNodesInternal().forEach(function (n, i) {
|
1274 | return fn.call(_this18, _this18.wrap(n), i);
|
1275 | });
|
1276 | return this;
|
1277 | }
|
1278 |
|
1279 | return forEach;
|
1280 | }()
|
1281 |
|
1282 | |
1283 |
|
1284 |
|
1285 |
|
1286 |
|
1287 |
|
1288 |
|
1289 |
|
1290 | }, {
|
1291 | key: 'map',
|
1292 | value: function () {
|
1293 | function map(fn) {
|
1294 | var _this19 = this;
|
1295 |
|
1296 | return this.getNodesInternal().map(function (n, i) {
|
1297 | return fn.call(_this19, _this19.wrap(n), i);
|
1298 | });
|
1299 | }
|
1300 |
|
1301 | return map;
|
1302 | }()
|
1303 |
|
1304 | |
1305 |
|
1306 |
|
1307 |
|
1308 |
|
1309 |
|
1310 |
|
1311 |
|
1312 |
|
1313 | }, {
|
1314 | key: 'reduce',
|
1315 | value: function () {
|
1316 | function reduce(fn) {
|
1317 | var _this20 = this;
|
1318 |
|
1319 | var initialValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
1320 |
|
1321 | if (arguments.length > 1) {
|
1322 | return this.getNodesInternal().reduce(function (accum, n, i) {
|
1323 | return fn.call(_this20, accum, _this20.wrap(n), i);
|
1324 | }, initialValue);
|
1325 | }
|
1326 | return this.getNodesInternal().reduce(function (accum, n, i) {
|
1327 | return fn.call(_this20, i === 1 ? _this20.wrap(accum) : accum, _this20.wrap(n), i);
|
1328 | });
|
1329 | }
|
1330 |
|
1331 | return reduce;
|
1332 | }()
|
1333 |
|
1334 | |
1335 |
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 |
|
1341 |
|
1342 |
|
1343 | }, {
|
1344 | key: 'reduceRight',
|
1345 | value: function () {
|
1346 | function reduceRight(fn) {
|
1347 | var _this21 = this;
|
1348 |
|
1349 | var initialValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
1350 |
|
1351 | if (arguments.length > 1) {
|
1352 | return this.getNodesInternal().reduceRight(function (accum, n, i) {
|
1353 | return fn.call(_this21, accum, _this21.wrap(n), i);
|
1354 | }, initialValue);
|
1355 | }
|
1356 | return this.getNodesInternal().reduceRight(function (accum, n, i) {
|
1357 | return fn.call(_this21, i === 1 ? _this21.wrap(accum) : accum, _this21.wrap(n), i);
|
1358 | });
|
1359 | }
|
1360 |
|
1361 | return reduceRight;
|
1362 | }()
|
1363 |
|
1364 | |
1365 |
|
1366 |
|
1367 |
|
1368 |
|
1369 |
|
1370 |
|
1371 |
|
1372 |
|
1373 | }, {
|
1374 | key: 'slice',
|
1375 | value: function () {
|
1376 | function slice(begin, end) {
|
1377 | return this.wrap(this.getNodesInternal().slice(begin, end));
|
1378 | }
|
1379 |
|
1380 | return slice;
|
1381 | }()
|
1382 |
|
1383 | |
1384 |
|
1385 |
|
1386 |
|
1387 |
|
1388 |
|
1389 |
|
1390 | }, {
|
1391 | key: 'some',
|
1392 | value: function () {
|
1393 | function some(selector) {
|
1394 | if (this[ROOT] === this) {
|
1395 | throw new Error('ReactWrapper::some() can not be called on the root');
|
1396 | }
|
1397 | var predicate = (0, _selectors.buildPredicate)(selector);
|
1398 | return this.getNodesInternal().some(predicate);
|
1399 | }
|
1400 |
|
1401 | return some;
|
1402 | }()
|
1403 |
|
1404 | |
1405 |
|
1406 |
|
1407 |
|
1408 |
|
1409 |
|
1410 |
|
1411 | }, {
|
1412 | key: 'someWhere',
|
1413 | value: function () {
|
1414 | function someWhere(predicate) {
|
1415 | var _this22 = this;
|
1416 |
|
1417 | return this.getNodesInternal().some(function (n, i) {
|
1418 | return predicate.call(_this22, _this22.wrap(n), i);
|
1419 | });
|
1420 | }
|
1421 |
|
1422 | return someWhere;
|
1423 | }()
|
1424 |
|
1425 | |
1426 |
|
1427 |
|
1428 |
|
1429 |
|
1430 |
|
1431 |
|
1432 | }, {
|
1433 | key: 'every',
|
1434 | value: function () {
|
1435 | function every(selector) {
|
1436 | var predicate = (0, _selectors.buildPredicate)(selector);
|
1437 | return this.getNodesInternal().every(predicate);
|
1438 | }
|
1439 |
|
1440 | return every;
|
1441 | }()
|
1442 |
|
1443 | |
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 | }, {
|
1451 | key: 'everyWhere',
|
1452 | value: function () {
|
1453 | function everyWhere(predicate) {
|
1454 | var _this23 = this;
|
1455 |
|
1456 | return this.getNodesInternal().every(function (n, i) {
|
1457 | return predicate.call(_this23, _this23.wrap(n), i);
|
1458 | });
|
1459 | }
|
1460 |
|
1461 | return everyWhere;
|
1462 | }()
|
1463 |
|
1464 | |
1465 |
|
1466 |
|
1467 |
|
1468 |
|
1469 |
|
1470 |
|
1471 |
|
1472 |
|
1473 | }, {
|
1474 | key: 'flatMap',
|
1475 | value: function () {
|
1476 | function flatMap(fn) {
|
1477 | var _this24 = this;
|
1478 |
|
1479 | var nodes = this.getNodesInternal().map(function (n, i) {
|
1480 | return fn.call(_this24, _this24.wrap(n), i);
|
1481 | });
|
1482 | var flattened = (0, _arrayPrototype2['default'])(nodes, 1);
|
1483 | return this.wrap(flattened.filter(Boolean));
|
1484 | }
|
1485 |
|
1486 | return flatMap;
|
1487 | }()
|
1488 |
|
1489 | |
1490 |
|
1491 |
|
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 | }, {
|
1498 | key: 'findWhere',
|
1499 | value: function () {
|
1500 | function findWhere(predicate) {
|
1501 | var _this25 = this;
|
1502 |
|
1503 | return findWhereUnwrapped(this, function (n) {
|
1504 | return predicate(_this25.wrap(n));
|
1505 | });
|
1506 | }
|
1507 |
|
1508 | return findWhere;
|
1509 | }()
|
1510 |
|
1511 | |
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 | }, {
|
1519 | key: 'get',
|
1520 | value: function () {
|
1521 | function get(index) {
|
1522 | return this.getElements()[index];
|
1523 | }
|
1524 |
|
1525 | return get;
|
1526 | }()
|
1527 |
|
1528 | /**
|
1529 | * Returns a wrapper around the node at a given index of the current wrapper.
|
1530 | *
|
1531 | * @param {Number} index
|
1532 | * @returns {ReactWrapper}
|
1533 | */
|
1534 |
|
1535 | }, {
|
1536 | key: 'at',
|
1537 | value: function () {
|
1538 | function at(index) {
|
1539 | var nodes = this.getNodesInternal();
|
1540 | if (index < nodes.length) {
|
1541 | return this.wrap(nodes[index]);
|
1542 | }
|
1543 | return this.wrap([]);
|
1544 | }
|
1545 |
|
1546 | return at;
|
1547 | }()
|
1548 |
|
1549 | |
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 | }, {
|
1556 | key: 'first',
|
1557 | value: function () {
|
1558 | function first() {
|
1559 | return this.at(0);
|
1560 | }
|
1561 |
|
1562 | return first;
|
1563 | }()
|
1564 |
|
1565 | |
1566 |
|
1567 |
|
1568 |
|
1569 |
|
1570 |
|
1571 | }, {
|
1572 | key: 'last',
|
1573 | value: function () {
|
1574 | function last() {
|
1575 | return this.at(this.length - 1);
|
1576 | }
|
1577 |
|
1578 | return last;
|
1579 | }()
|
1580 |
|
1581 | |
1582 |
|
1583 |
|
1584 |
|
1585 |
|
1586 |
|
1587 | }, {
|
1588 | key: 'isEmpty',
|
1589 | value: function () {
|
1590 | function isEmpty() {
|
1591 |
|
1592 | console.warn('Enzyme::Deprecated method isEmpty() called, use exists() instead.');
|
1593 | return !this.exists();
|
1594 | }
|
1595 |
|
1596 | return isEmpty;
|
1597 | }()
|
1598 |
|
1599 | |
1600 |
|
1601 |
|
1602 |
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 | }, {
|
1608 | key: 'exists',
|
1609 | value: function () {
|
1610 | function exists() {
|
1611 | var selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
1612 |
|
1613 | if (arguments.length > 0 && typeof selector !== 'string') {
|
1614 | throw new TypeError('`selector` argument must be a string, if present.');
|
1615 | }
|
1616 | return typeof selector === 'string' ? this.find(selector).exists() : this.length > 0;
|
1617 | }
|
1618 |
|
1619 | return exists;
|
1620 | }()
|
1621 |
|
1622 | |
1623 |
|
1624 |
|
1625 |
|
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 |
|
1631 | }, {
|
1632 | key: 'single',
|
1633 | value: function () {
|
1634 | function single(name, fn) {
|
1635 | var fnName = typeof name === 'string' ? name : 'unknown';
|
1636 | var callback = typeof fn === 'function' ? fn : name;
|
1637 | if (this.length !== 1) {
|
1638 | throw new Error('Method \u201C' + fnName + '\u201D is only meant to be run on a single node. ' + String(this.length) + ' found instead.');
|
1639 | }
|
1640 | return callback.call(this, this.getNodeInternal());
|
1641 | }
|
1642 |
|
1643 | return single;
|
1644 | }()
|
1645 |
|
1646 | |
1647 |
|
1648 |
|
1649 |
|
1650 |
|
1651 |
|
1652 |
|
1653 |
|
1654 | }, {
|
1655 | key: 'wrap',
|
1656 | value: function () {
|
1657 | function wrap(node) {
|
1658 | var root = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this[ROOT];
|
1659 |
|
1660 | if (node instanceof ReactWrapper) {
|
1661 | return node;
|
1662 | }
|
1663 |
|
1664 | for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
1665 | args[_key - 2] = arguments[_key];
|
1666 | }
|
1667 |
|
1668 | return new (Function.prototype.bind.apply(ReactWrapper, [null].concat([node, root], args)))();
|
1669 | }
|
1670 |
|
1671 | return wrap;
|
1672 | }()
|
1673 |
|
1674 | |
1675 |
|
1676 |
|
1677 |
|
1678 |
|
1679 |
|
1680 |
|
1681 |
|
1682 |
|
1683 | }, {
|
1684 | key: 'debug',
|
1685 | value: function () {
|
1686 | function debug() {
|
1687 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
1688 |
|
1689 | return (0, _Debug.debugNodes)(this.getNodesInternal(), options);
|
1690 | }
|
1691 |
|
1692 | return debug;
|
1693 | }()
|
1694 |
|
1695 | |
1696 |
|
1697 |
|
1698 |
|
1699 |
|
1700 |
|
1701 |
|
1702 | }, {
|
1703 | key: 'tap',
|
1704 | value: function () {
|
1705 | function tap(intercepter) {
|
1706 | intercepter(this);
|
1707 | return this;
|
1708 | }
|
1709 |
|
1710 | return tap;
|
1711 | }()
|
1712 |
|
1713 | |
1714 |
|
1715 |
|
1716 |
|
1717 |
|
1718 |
|
1719 |
|
1720 |
|
1721 |
|
1722 |
|
1723 | }, {
|
1724 | key: 'detach',
|
1725 | value: function () {
|
1726 | function detach() {
|
1727 | if (this[ROOT] !== this) {
|
1728 | throw new Error('ReactWrapper::detach() can only be called on the root');
|
1729 | }
|
1730 | if (!this[OPTIONS].attachTo) {
|
1731 | throw new Error('ReactWrapper::detach() can only be called on when the `attachTo` option was passed into `mount()`.');
|
1732 | }
|
1733 | this[RENDERER].unmount();
|
1734 | }
|
1735 |
|
1736 | return detach;
|
1737 | }()
|
1738 |
|
1739 | |
1740 |
|
1741 |
|
1742 |
|
1743 |
|
1744 |
|
1745 |
|
1746 | }, {
|
1747 | key: 'hostNodes',
|
1748 | value: function () {
|
1749 | function hostNodes() {
|
1750 | return this.filterWhere(function (n) {
|
1751 | return typeof n.type() === 'string';
|
1752 | });
|
1753 | }
|
1754 |
|
1755 | return hostNodes;
|
1756 | }()
|
1757 | }]);
|
1758 |
|
1759 | return ReactWrapper;
|
1760 | }();
|
1761 |
|
1762 | if (_Utils.ITERATOR_SYMBOL) {
|
1763 | Object.defineProperty(ReactWrapper.prototype, _Utils.ITERATOR_SYMBOL, {
|
1764 | configurable: true,
|
1765 | value: function () {
|
1766 | function iterator() {
|
1767 | var _ref;
|
1768 |
|
1769 | var iter = this[NODES][_Utils.ITERATOR_SYMBOL]();
|
1770 | var adapter = (0, _getAdapter2['default'])(this[OPTIONS]);
|
1771 | return _ref = {}, _defineProperty(_ref, _Utils.ITERATOR_SYMBOL, function () {
|
1772 | return this;
|
1773 | }), _defineProperty(_ref, 'next', function () {
|
1774 | function next() {
|
1775 | var next = iter.next();
|
1776 | if (next.done) {
|
1777 | return { done: true };
|
1778 | }
|
1779 | return {
|
1780 | done: false,
|
1781 | value: adapter.nodeToElement(next.value)
|
1782 | };
|
1783 | }
|
1784 |
|
1785 | return next;
|
1786 | }()), _ref;
|
1787 | }
|
1788 |
|
1789 | return iterator;
|
1790 | }()
|
1791 | });
|
1792 | }
|
1793 |
|
1794 | function privateWarning(prop, extraMessage) {
|
1795 | Object.defineProperty(ReactWrapper.prototype, prop, {
|
1796 | get: function () {
|
1797 | function get() {
|
1798 | throw new Error('\n Attempted to access ReactWrapper::' + String(prop) + ', which was previously a private property on\n Enzyme ReactWrapper instances, but is no longer and should not be relied upon.\n ' + String(extraMessage) + '\n ');
|
1799 | }
|
1800 |
|
1801 | return get;
|
1802 | }(),
|
1803 |
|
1804 | enumerable: false,
|
1805 | configurable: false
|
1806 | });
|
1807 | }
|
1808 |
|
1809 | privateWarning('node', 'Consider using the getElement() method instead.');
|
1810 | privateWarning('nodes', 'Consider using the getElements() method instead.');
|
1811 | privateWarning('renderer', '');
|
1812 | privateWarning('options', '');
|
1813 | privateWarning('complexSelector', '');
|
1814 |
|
1815 | exports['default'] = ReactWrapper; |
\ | No newline at end of file |