import { RefFindNode } from '@fluentui/react-component-ref'; import { mount } from 'enzyme'; import * as React from 'react'; import { CompositeClass, CompositeFunction, DOMClass, DOMFunction } from './fixtures'; const testInnerRef = (Component: React.ElementType) => { const innerRef = jest.fn(); const node = mount( , ).getDOMNode(); expect(innerRef).toHaveBeenCalledTimes(1); expect(innerRef).toHaveBeenCalledWith(node); }; describe('RefFindNode', () => { describe('innerRef', () => { it('returns node from a functional component with DOM node', () => { testInnerRef(DOMFunction); }); it('returns node from a functional component', () => { testInnerRef(CompositeFunction); }); it('returns node from a class component with DOM node', () => { testInnerRef(DOMClass); }); it('returns node from a class component', () => { testInnerRef(CompositeClass); }); it('returns "null" after unmount', () => { const innerRef = jest.fn(); const wrapper = mount( , ); innerRef.mockClear(); wrapper.unmount(); expect(innerRef).toHaveBeenCalledTimes(1); expect(innerRef).toHaveBeenCalledWith(null); }); it('passes an updated node', () => { const innerRef = jest.fn(); const wrapper = mount(
, ); expect(innerRef).toHaveBeenCalledWith(expect.objectContaining({ tagName: 'DIV' })); wrapper.setProps({ children: