UNPKG

49.8 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _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
9var _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
11var _object = require('object.assign');
12
13var _object2 = _interopRequireDefault(_object);
14
15var _cheerio = require('cheerio');
16
17var _cheerio2 = _interopRequireDefault(_cheerio);
18
19var _arrayPrototype = require('array.prototype.flat');
20
21var _arrayPrototype2 = _interopRequireDefault(_arrayPrototype);
22
23var _Utils = require('./Utils');
24
25var _getAdapter = require('./getAdapter');
26
27var _getAdapter2 = _interopRequireDefault(_getAdapter);
28
29var _Debug = require('./Debug');
30
31var _RSTTraversal = require('./RSTTraversal');
32
33var _selectors = require('./selectors');
34
35function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36
37function _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
39function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
40
41var NODE = (0, _Utils.sym)('__node__');
42var NODES = (0, _Utils.sym)('__nodes__');
43var RENDERER = (0, _Utils.sym)('__renderer__');
44var UNRENDERED = (0, _Utils.sym)('__unrendered__');
45var ROOT = (0, _Utils.sym)('__root__');
46var OPTIONS = (0, _Utils.sym)('__options__');
47
48/**
49 * Finds all nodes in the current wrapper nodes' render trees that match the provided predicate
50 * function.
51 *
52 * @param {ReactWrapper} wrapper
53 * @param {Function} predicate
54 * @param {Function} filter
55 * @returns {ReactWrapper}
56 */
57function 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 * Returns a new wrapper instance with only the nodes of the current wrapper instance that match
67 * the provided predicate function.
68 *
69 * @param {ReactWrapper} wrapper
70 * @param {Function} predicate
71 * @returns {ReactWrapper}
72 */
73function filterWhereUnwrapped(wrapper, predicate) {
74 return wrapper.wrap(wrapper.getNodesInternal().filter(predicate).filter(Boolean));
75}
76
77function nodeParents(wrapper, node) {
78 return (0, _RSTTraversal.parentsOfNode)(node, wrapper[ROOT].getNodeInternal());
79}
80
81function 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 * @class ReactWrapper
97 */
98
99var 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 * Returns the root wrapper
133 *
134 * @return {ReactWrapper}
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 * Returns the wrapped component.
150 *
151 * @return {ReactComponent}
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 * Returns the the wrapped components.
169 *
170 * @return {Array<ReactComponent>}
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 * Returns the wrapped ReactElement.
185 *
186 * @return {ReactElement}
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 * Returns the wrapped ReactElements.
204 *
205 * @return {Array<ReactElement>}
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 // eslint-disable-next-line class-methods-use-this
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 // eslint-disable-next-line class-methods-use-this
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 * Returns the outer most DOMComponent of the current wrapper.
244 *
245 * NOTE: can only be called on a wrapper of a single node.
246 *
247 * @returns {DOMComponent}
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 * If the root component contained a ref, you can access it here and get the relevant
265 * react component instance or HTML element instance.
266 *
267 * NOTE: can only be called on a wrapper instance that is also the root instance.
268 *
269 * @param {String} refname
270 * @returns {ReactComponent | HTMLElement}
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 * Returns the wrapper's underlying instance.
288 *
289 * Example:
290 * ```
291 * const wrapper = mount(<MyComponent />);
292 * const inst = wrapper.instance();
293 * expect(inst).to.be.instanceOf(MyComponent);
294 * ```
295 * @returns {ReactComponent|DOMComponent}
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 * Forces a re-render. Useful to run before checking the render output if something external
313 * may be updating the state of the component somewhere.
314 *
315 * NOTE: can only be called on a wrapper instance that is also the root instance.
316 *
317 * @returns {ReactWrapper}
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 * A method that unmounts the component. This can be used to simulate a component going through
336 * and unmount/mount lifecycle.
337 *
338 * @returns {ReactWrapper}
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 * A method that re-mounts the component, if it is not currently mounted.
362 * This can be used to simulate a component going through
363 * an unmount/mount lifecycle.
364 *
365 * @returns {ReactWrapper}
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 * A method that sets the props of the root component, and re-renders. Useful for when you are
388 * wanting to test how the component behaves over time with changing props. Calling this, for
389 * instance, will call the `componentWillReceiveProps` lifecycle method.
390 *
391 * Similar to `setState`, this method accepts a props object and will merge it in with the already
392 * existing props.
393 *
394 * NOTE: can only be called on a wrapper instance that is also the root instance.
395 *
396 * @param {Object} props object
397 * @param {Function} cb - callback function
398 * @returns {ReactWrapper}
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 * A method to invoke `setState` on the root component instance similar to how you might in the
431 * definition of the component, and re-renders. This method is useful for testing your component
432 * in hard to achieve states, however should be used sparingly. If possible, you should utilize
433 * your component's external API in order to get it into whatever state you want to test, in order
434 * to be as accurate of a test as possible. This is not always practical, however.
435 *
436 * NOTE: can only be called on a wrapper instance that is also the root instance.
437 *
438 * @param {Object} state to merge
439 * @param {Function} cb - callback function
440 * @returns {ReactWrapper}
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 * A method that sets the context of the root component, and re-renders. Useful for when you are
480 * wanting to test how the component behaves over time with changing contexts.
481 *
482 * NOTE: can only be called on a wrapper instance that is also the root instance.
483 *
484 * @param {Object} context object
485 * @returns {ReactWrapper}
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 * Whether or not a given react element exists in the mount render tree.
511 *
512 * Example:
513 * ```
514 * const wrapper = mount(<MyComponent />);
515 * expect(wrapper.contains(<div className="foo bar" />)).to.equal(true);
516 * ```
517 *
518 * @param {ReactElement|Array<ReactElement>} nodeOrNodes
519 * @returns {Boolean}
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 * Whether or not a given react element exists in the current render tree.
544 * It will determine if one of the wrappers element "looks like" the expected
545 * element by checking if all props of the expected element are present
546 * on the wrappers element and equals to each other.
547 *
548 * Example:
549 * ```
550 * // MyComponent outputs <div><div class="foo">Hello</div></div>
551 * const wrapper = mount(<MyComponent />);
552 * expect(wrapper.containsMatchingElement(<div>Hello</div>)).to.equal(true);
553 * ```
554 *
555 * @param {ReactElement} node
556 * @returns {Boolean}
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 * Whether or not all the given react elements exists in the current render tree.
581 * It will determine if one of the wrappers element "looks like" the expected
582 * element by checking if all props of the expected element are present
583 * on the wrappers element and equals to each other.
584 *
585 * Example:
586 * ```
587 * const wrapper = mount(<MyComponent />);
588 * expect(wrapper.containsAllMatchingElements([
589 * <div>Hello</div>,
590 * <div>Goodbye</div>,
591 * ])).to.equal(true);
592 * ```
593 *
594 * @param {Array<ReactElement>} nodes
595 * @returns {Boolean}
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 * Whether or not one of the given react elements exists in the current render tree.
618 * It will determine if one of the wrappers element "looks like" the expected
619 * element by checking if all props of the expected element are present
620 * on the wrappers element and equals to each other.
621 *
622 * Example:
623 * ```
624 * const wrapper = mount(<MyComponent />);
625 * expect(wrapper.containsAnyMatchingElements([
626 * <div>Hello</div>,
627 * <div>Goodbye</div>,
628 * ])).to.equal(true);
629 * ```
630 *
631 * @param {Array<ReactElement>} nodes
632 * @returns {Boolean}
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 * Whether or not a given react element exists in the render tree.
651 *
652 * Example:
653 * ```
654 * const wrapper = mount(<MyComponent />);
655 * expect(wrapper.contains(<div className="foo bar" />)).to.equal(true);
656 * ```
657 *
658 * @param {ReactElement} node
659 * @returns {Boolean}
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 * Whether or not a given react element matches the render tree.
678 * Match is based on the expected element and not on wrapper root node.
679 * It will determine if the wrapper root node "looks like" the expected
680 * element by checking if all props of the expected element are present
681 * on the wrapper root node and equals to each other.
682 *
683 * Example:
684 * ```
685 * // MyComponent outputs <div class="foo">Hello</div>
686 * const wrapper = mount(<MyComponent />);
687 * expect(wrapper.matchesElement(<div>Hello</div>)).to.equal(true);
688 * ```
689 *
690 * @param {ReactElement} node
691 * @returns {Boolean}
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 * Finds every node in the render tree of the current wrapper that matches the provided selector.
714 *
715 * @param {String|Function} selector
716 * @returns {ReactWrapper}
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 * Returns whether or not current node matches a provided selector.
731 *
732 * NOTE: can only be called on a wrapper of a single node.
733 *
734 * @param {String|Function} selector
735 * @returns {boolean}
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 * Returns true if the component rendered nothing, i.e., null or false.
753 *
754 * @returns {boolean}
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 * Returns a new wrapper instance with only the nodes of the current wrapper instance that match
771 * the provided predicate function.
772 *
773 * @param {Function} predicate
774 * @returns {ReactWrapper}
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 * Returns a new wrapper instance with only the nodes of the current wrapper instance that match
793 * the provided selector.
794 *
795 * @param {String|Function} selector
796 * @returns {ReactWrapper}
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 * Returns a new wrapper instance with only the nodes of the current wrapper that did not match
812 * the provided selector. Essentially the inverse of `filter`.
813 *
814 * @param {String|Function} selector
815 * @returns {ReactWrapper}
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 * Returns a string of the rendered text of the current render tree. This function should be
833 * looked at with skepticism if being used to test what the actual HTML output of the component
834 * will be. If that is what you would like to test, use enzyme's `render` function instead.
835 *
836 * NOTE: can only be called on a wrapper of a single node.
837 *
838 * @returns {String}
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 * Returns the HTML of the node.
857 *
858 * NOTE: can only be called on a wrapper of a single node.
859 *
860 * @returns {String}
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 * Returns the current node rendered to HTML and wrapped in a CheerioWrapper.
882 *
883 * NOTE: can only be called on a wrapper of a single node.
884 *
885 * @returns {CheerioWrapper}
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 * Used to simulate events. Pass an eventname and (optionally) event arguments. This method of
901 * testing events should be met with some skepticism.
902 *
903 * @param {String} event
904 * @param {Object} mock (optional)
905 * @returns {ReactWrapper}
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 * Used to simulate throwing a rendering error. Pass an error to throw.
928 *
929 * @param {String} error
930 * @returns {ReactWrapper}
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 * Returns the props hash for the root node of the wrapper.
966 *
967 * NOTE: can only be called on a wrapper of a single node.
968 *
969 * @returns {Object}
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 * Returns the state hash for the root node of the wrapper. Optionally pass in a prop name and it
984 * will return just that value.
985 *
986 * NOTE: can only be called on a wrapper of a single node.
987 *
988 * @param {String} name (optional)
989 * @returns {*}
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 * Returns the context hash for the root node of the wrapper.
1018 * Optionally pass in a prop name and it will return just that value.
1019 *
1020 * NOTE: can only be called on a wrapper of a single node.
1021 *
1022 * @param {String} name (optional)
1023 * @returns {*}
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 * Returns a new wrapper with all of the children of the current wrapper.
1053 *
1054 * @param {String|Function} [selector]
1055 * @returns {ReactWrapper}
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 * Returns a new wrapper with a specific child
1075 *
1076 * @param {Number} [index]
1077 * @returns {ReactWrapper}
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 * Returns a wrapper around all of the parents/ancestors of the wrapper. Does not include the node
1096 * in the current wrapper.
1097 *
1098 * NOTE: can only be called on a wrapper of a single node.
1099 *
1100 * @param {String|Function} [selector]
1101 * @returns {ReactWrapper}
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 * Returns a wrapper around the immediate parent of the current node.
1121 *
1122 * @returns {ReactWrapper}
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 * @param {String|Function} selector
1140 * @returns {ReactWrapper}
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 * Returns the value of prop with the given name of the root node.
1161 *
1162 * @param {String} propName
1163 * @returns {*}
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 * Returns the key assigned to the current node.
1178 *
1179 * @returns {String}
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 * Returns the type of the root node of this wrapper. If it's a composite component, this will be
1196 * the component constructor. If it's native DOM node, it will be a string.
1197 *
1198 * @returns {String|Function}
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 * Returns the name of the root node of this wrapper.
1215 *
1216 * In order of precedence => type.displayName -> type.name -> type.
1217 *
1218 * @returns {String}
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 * Returns whether or not the current root node has the given class name or not.
1236 *
1237 * NOTE: can only be called on a wrapper of a single node.
1238 *
1239 * @param {String} className
1240 * @returns {Boolean}
1241 */
1242
1243 }, {
1244 key: 'hasClass',
1245 value: function () {
1246 function hasClass(className) {
1247 if (className && className.indexOf('.') !== -1) {
1248 // eslint-disable-next-line no-console
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 * Iterates through each node of the current wrapper and executes the provided function with a
1261 * wrapper around the corresponding node passed in as the first argument.
1262 *
1263 * @param {Function} fn
1264 * @returns {ReactWrapper}
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 * Maps the current array of nodes to another array. Each node is passed in as a `ReactWrapper`
1284 * to the map function.
1285 *
1286 * @param {Function} fn
1287 * @returns {Array}
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 * Reduces the current array of nodes to another array.
1306 * Each node is passed in as a `ShallowWrapper` to the reducer function.
1307 *
1308 * @param {Function} fn - the reducer function
1309 * @param {*} initialValue - the initial value
1310 * @returns {*}
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 * Reduces the current array of nodes to another array, from right to left. Each node is passed
1336 * in as a `ShallowWrapper` to the reducer function.
1337 *
1338 * @param {Function} fn - the reducer function
1339 * @param {*} initialValue - the initial value
1340 * @returns {*}
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 * Returns a new wrapper with a subset of the nodes of the original wrapper, according to the
1366 * rules of `Array#slice`.
1367 *
1368 * @param {Number} begin
1369 * @param {Number} end
1370 * @returns {ShallowWrapper}
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 * Returns whether or not any of the nodes in the wrapper match the provided selector.
1385 *
1386 * @param {Function|String} selector
1387 * @returns {Boolean}
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 * Returns whether or not any of the nodes in the wrapper pass the provided predicate function.
1406 *
1407 * @param {Function} predicate
1408 * @returns {Boolean}
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 * Returns whether or not all of the nodes in the wrapper match the provided selector.
1427 *
1428 * @param {Function|String} selector
1429 * @returns {Boolean}
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 * Returns whether or not any of the nodes in the wrapper pass the provided predicate function.
1445 *
1446 * @param {Function} predicate
1447 * @returns {Boolean}
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 * Utility method used to create new wrappers with a mapping function that returns an array of
1466 * nodes in response to a single node wrapper. The returned wrapper is a single wrapper around
1467 * all of the mapped nodes flattened (and de-duplicated).
1468 *
1469 * @param {Function} fn
1470 * @returns {ReactWrapper}
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 * Finds all nodes in the current wrapper nodes' render trees that match the provided predicate
1491 * function.
1492 *
1493 * @param {Function} predicate
1494 * @returns {ReactWrapper}
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 * Returns the node at a given index of the current wrapper.
1513 *
1514 * @param {Number} index
1515 * @returns {ReactElement}
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 * Returns a wrapper around the first node of the current wrapper.
1551 *
1552 * @returns {ReactWrapper}
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 * Returns a wrapper around the last node of the current wrapper.
1567 *
1568 * @returns {ReactWrapper}
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 * Delegates to exists()
1583 *
1584 * @returns {boolean}
1585 */
1586
1587 }, {
1588 key: 'isEmpty',
1589 value: function () {
1590 function isEmpty() {
1591 // eslint-disable-next-line no-console
1592 console.warn('Enzyme::Deprecated method isEmpty() called, use exists() instead.');
1593 return !this.exists();
1594 }
1595
1596 return isEmpty;
1597 }()
1598
1599 /**
1600 * Returns true if the current wrapper has nodes. False otherwise.
1601 * If called with a selector it returns `.find(selector).exists()` instead.
1602 *
1603 * @param {String|Function} selector (optional)
1604 * @returns {boolean}
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 * Utility method that throws an error if the current instance has a length other than one.
1624 * This is primarily used to enforce that certain methods are only run on a wrapper when it is
1625 * wrapping a single node.
1626 *
1627 * @param {Function} fn
1628 * @returns {*}
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 * Helpful utility method to create a new wrapper with the same root as the current wrapper, with
1648 * any nodes passed in as the first parameter automatically wrapped.
1649 *
1650 * @param {ReactWrapper|ReactElement|Array<ReactElement>} node
1651 * @returns {ReactWrapper}
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 * Returns an HTML-like string of the shallow render for debugging purposes.
1676 *
1677 * @param {Object} [options] - Property bag of additional options.
1678 * @param {boolean} [options.ignoreProps] - if true, props are omitted from the string.
1679 * @param {boolean} [options.verbose] - if true, arrays and objects to be verbosely printed.
1680 * @returns {String}
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 * Invokes intercepter and returns itself. intercepter is called with itself.
1697 * This is helpful when debugging nodes in method chains.
1698 * @param fn
1699 * @returns {ReactWrapper}
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 * Detaches the react tree from the DOM. Runs `ReactDOM.unmountComponentAtNode()` under the hood.
1715 *
1716 * This method will most commonly be used as a "cleanup" method if you decide to use the
1717 * `attachTo` option in `mount(node, options)`.
1718 *
1719 * The method is intentionally not "fluent" (in that it doesn't return `this`) because you should
1720 * not be doing anything with this wrapper after this method is called.
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 * Strips out all the not host-nodes from the list of nodes
1741 *
1742 * This method is useful if you want to check for the presence of host nodes
1743 * (actually rendered HTML elements) ignoring the React nodes.
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
1762if (_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
1794function 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
1809privateWarning('node', 'Consider using the getElement() method instead.');
1810privateWarning('nodes', 'Consider using the getElements() method instead.');
1811privateWarning('renderer', '');
1812privateWarning('options', '');
1813privateWarning('complexSelector', '');
1814
1815exports['default'] = ReactWrapper;
\No newline at end of file