import * as React from "react" ; import * as sinon from "sinon" ; import { act , renderHook } from "@testing-library/react-hooks" ; import { mergeRefs , useRefs } from "../../../core-react/utils/hooks/useRefs" ; describe ( "useRefs" , ( ) => { it ( "should set ref objects and invoke ref callbacks" , ( ) => { let ref = { current : null } ; let mutableRef = { current : null } ; const callbackRef = sinon . spy ( ( _ ) => { } ) ; const { result } = renderHook ( ( ) => { ref = React . useRef < string > ( null ) ; mutableRef = React . useRef < string | null > ( null ) ; return useRefs ( ref , mutableRef , callbackRef ) ; } ) ; act ( ( ) => { result . current ( "abc" ) ; } ) ; ref . current ! . should . eq ( "abc" ) ; mutableRef . current ! . should . eq ( "abc" ) ; callbackRef . calledOnceWithExactly ( "abc" ) . should . true ; } ) ; } ) ; describe ( "mergeRefs" , ( ) => { it ( "should set ref objects and invoke ref callbacks" , ( ) => { let ref = { current : null } ; let mutableRef = { current : null } ; const callbackRef = sinon . spy ( ( _ ) => { } ) ; const { result } = renderHook ( ( ) => { ref = React . useRef < string > ( null ) ; mutableRef = React . useRef < string | null > ( null ) ; return mergeRefs ( ref , mutableRef , callbackRef ) ; } ) ; act ( ( ) => { result . current ( "abc" ) ; } ) ; ref . current ! . should . eq ( "abc" ) ; mutableRef . current ! . should . eq ( "abc" ) ; callbackRef . calledOnceWithExactly ( "abc" ) . should . true ; } ) ; } ) ;