I have a custom hook that can have an optional ref passed to it as a property of an object that the hook takes as an argument:
export const useShortcuts = ({ ref }) => {
useEffect(() => {
const trapper = new mousetrap(ref.current);
The code works but I am now trying to write tests for this using react-testing-library
and the @testing-library/react-hooks library.
I am using renderHook
from @testing-library/react-hooks but I don't know how to create the ref or mock the ref outside of a component.
it('should create shortcuts with no ref', () => {
const ref = ????? // how do I do this
const { result } = renderHook(() => useShortcuts({ ref }), {
initialProps: true
});
});