aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/helpers/refs.test.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/helpers/refs.test.tsx')
-rw-r--r--src/utils/helpers/refs.test.tsx28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/utils/helpers/refs.test.tsx b/src/utils/helpers/refs.test.tsx
new file mode 100644
index 0000000..93e5f89
--- /dev/null
+++ b/src/utils/helpers/refs.test.tsx
@@ -0,0 +1,28 @@
+import { describe, it, jest } from '@jest/globals';
+import { render } from '@testing-library/react';
+import { forwardRef, useImperativeHandle } from 'react';
+import { mergeRefs } from './refs';
+
+const refValue = 'minus architecto qui';
+const TestComponentWithForwardedRef = forwardRef((_, ref) => {
+ useImperativeHandle(ref, () => refValue);
+ return null;
+});
+TestComponentWithForwardedRef.displayName = 'TestComponentWithForwardedRef';
+
+describe('merge-refs', () => {
+ it('can merge a ref function with a ref object', () => {
+ const refFn = jest.fn();
+ const refObj = { current: null };
+
+ const TestComponent = () => (
+ <TestComponentWithForwardedRef ref={mergeRefs([refFn, refObj])} />
+ );
+
+ render(<TestComponent />);
+
+ expect(refFn).toHaveBeenCalledTimes(1);
+ expect(refFn).toHaveBeenLastCalledWith(refValue);
+ expect(refObj.current).toBe(refValue);
+ });
+});