|
1 | 1 | import { render } from '@testing-library/react';
|
2 | 2 | import * as React from 'react';
|
3 | 3 | import findDOMNode, { isDOM } from '../src/Dom/findDOMNode';
|
| 4 | +import proxyObject from '../src/proxyObject'; |
4 | 5 |
|
5 | 6 | describe('findDOMNode', () => {
|
6 | 7 | it('base work', () => {
|
@@ -97,4 +98,35 @@ describe('findDOMNode', () => {
|
97 | 98 |
|
98 | 99 | expect(findDOMNode(elementRef.current)).toBe(container.querySelector('p'));
|
99 | 100 | });
|
| 101 | + |
| 102 | + it('with proxyObject', () => { |
| 103 | + const Demo = React.forwardRef((_, ref) => { |
| 104 | + const rootRef = React.useRef<HTMLDivElement>(null); |
| 105 | + const spanRef = React.useRef<HTMLParagraphElement>(null); |
| 106 | + |
| 107 | + React.useImperativeHandle(ref, () => |
| 108 | + proxyObject(rootRef.current, { |
| 109 | + nativeElement: spanRef.current, |
| 110 | + }), |
| 111 | + ); |
| 112 | + |
| 113 | + return ( |
| 114 | + <p ref={rootRef} id="root"> |
| 115 | + <span ref={spanRef} /> |
| 116 | + </p> |
| 117 | + ); |
| 118 | + }); |
| 119 | + |
| 120 | + const holderRef = React.createRef<any>(); |
| 121 | + const { container } = render( |
| 122 | + <React.StrictMode> |
| 123 | + <Demo ref={holderRef} /> |
| 124 | + </React.StrictMode>, |
| 125 | + ); |
| 126 | + |
| 127 | + expect(holderRef.current.id).toBe('root'); |
| 128 | + expect(findDOMNode(holderRef.current)).toBe( |
| 129 | + container.querySelector('span'), |
| 130 | + ); |
| 131 | + }); |
100 | 132 | });
|
0 commit comments