UNPKG

1.37 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = testRef;
11
12var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
13
14var React = _interopRequireWildcard(require("react"));
15
16var _chai = require("chai");
17
18function assertDOMNode(node) {
19 // duck typing a DOM node
20 (0, _chai.expect)((0, _typeof2.default)(node.nodeName)).to.equal('string');
21}
22/**
23 * Utility method to make assertions about the ref on an element
24 * @param {React.ReactElement} element - The element should have a component wrapped
25 * in withStyles as the root
26 * @param {function} mount - Should be returnvalue of createMount
27 * @param {function} onRef - Callback, first arg is the ref.
28 * Assert that the ref is a DOM node by default
29 */
30
31
32function testRef(element, mount) {
33 var onRef = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : assertDOMNode;
34 var ref = /*#__PURE__*/React.createRef();
35 var wrapper = mount( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.cloneElement(element, {
36 ref: ref
37 })));
38 onRef(ref.current, wrapper);
39}
\No newline at end of file