UNPKG

874 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.wrapsIntrinsicElement = wrapsIntrinsicElement;
7exports.default = findOutermostIntrinsic;
8
9/**
10 * checks if a given react wrapper wraps an intrinsic element i.e. a DOM node
11 *
12 * @param {import('enzyme').ReactWrapper} reactWrapper
13 * @returns {boolean} true if the given reactWrapper wraps an intrinsic element
14 */
15function wrapsIntrinsicElement(reactWrapper) {
16 return typeof reactWrapper.type() === 'string';
17}
18/**
19 * like ReactWrapper#getDOMNode() but returns a ReactWrapper
20 *
21 * @param {import('enzyme').ReactWrapper} reactWrapper
22 * @returns {import('enzyme').ReactWrapper} the wrapper for the outermost DOM node
23 */
24
25
26function findOutermostIntrinsic(reactWrapper) {
27 return reactWrapper.findWhere(function (n) {
28 return n.exists() && wrapsIntrinsicElement(n);
29 }).first();
30}
\No newline at end of file