UNPKG

894 BJavaScriptView Raw
1import * as React from 'react';
2import { expect } from 'chai';
3
4function assertDOMNode(node) {
5 // duck typing a DOM node
6 expect(typeof node.nodeName).to.equal('string');
7}
8/**
9 * Utility method to make assertions about the ref on an element
10 * @param {React.ReactElement} element - The element should have a component wrapped
11 * in withStyles as the root
12 * @param {function} mount - Should be returnvalue of createMount
13 * @param {function} onRef - Callback, first arg is the ref.
14 * Assert that the ref is a DOM node by default
15 */
16
17
18export default function testRef(element, mount, onRef = assertDOMNode) {
19 const ref = /*#__PURE__*/React.createRef();
20 const wrapper = mount( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.cloneElement(element, {
21 ref
22 })));
23 onRef(ref.current, wrapper);
24}
\No newline at end of file