1 | import * as React from 'react';
|
2 | import { expect } from 'chai';
|
3 |
|
4 | function 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 |
|
18 | export 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 |