I have some code like:
import { GoogleMap } from 'react-google-maps';
const GoogleMapContainer = () => {
const zoomToBounds = React.useCallback(
(map): void => map && bounds && map.fitBounds(bounds),
[bounds]
);
<GoogleMap ref={zoomToBounds}>
...
</GoogleMap>
}
and am trying to mock the GoogleMap with jest when I am testing GoogleMapContainer
jest.mock('react-google-maps', () => ({
GoogleMap: (props) => <div>{props.children}</div>,
}));
However, I get an error like:
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
I am unable to use forwardRef because jest complains about using functions from outside the scope. I get the same error if I try to create mock class-based component for GoogleMap.
How do I get around the ref error?