diff --git a/tests/useEnsuredForwardedRef.test.tsx b/tests/useEnsuredForwardedRef.test.tsx index fd7ed425ea..d6ba4fe63c 100644 --- a/tests/useEnsuredForwardedRef.test.tsx +++ b/tests/useEnsuredForwardedRef.test.tsx @@ -2,7 +2,7 @@ import React, { useRef } from 'react'; import ReactDOM from 'react-dom'; import { renderHook } from '@testing-library/react-hooks'; import TestUtils from 'react-dom/test-utils'; -import { useEnsuredForwardedRef } from '../src'; +import { ensuredForwardRef, useEnsuredForwardedRef } from '../src'; let container: HTMLDivElement; @@ -51,3 +51,24 @@ test('should return a valid ref when the forwarded ref is undefined', () => { expect(ensuredRef.current.id).toBe('test_id'); }); + +test('should return a valid ref when using the wrapper function style', () => { + const { result } = renderHook(() => { + const initialRef = useRef(null); + + const WrappedComponent = ensuredForwardRef((_props, ref) => { + return
; + }); + + TestUtils.act(() => { + ReactDOM.render(, container); + }); + + return { initialRef }; + }); + + const { initialRef } = result.current; + + expect(initialRef.current).toBeTruthy(); + expect(initialRef.current?.id).toBe('test_id'); +});