Testing <GoogleMap/> inside withScriptjs and withGoogleMap
See original GitHub issueThe element is as follows:
import React from 'react';
import { withGoogleMap, GoogleMap } from 'react-google-maps';
import withScriptjs from 'react-google-maps/lib/async/withScriptjs';
const AsyncGoogleMap = withScriptjs(withGoogleMap(({ onMapLoad }) => (
<GoogleMap
ref={onMapLoad}
defaultZoom={1}
defaultCenter={{ lat: 0, lng: 0 }}
/>
)));
export default AsyncGoogleMap;
The test is as follows:
import React from 'react';
import { mount } from 'enzyme';
import expect from 'expect';
import AsyncGoogleMap from './AsyncGoogleMap';
describe('AsyncGoogleMap component', () => {
let wrapper;
before((done) => {
wrapper = mount(<AsyncGoogleMap
googleMapURL={'https://maps.googleapis.com/maps/api/js'}
loadingElement={<div>Loading</div>}
containerElement={<div>Container</div>}
mapElement={<div>Map</div>}
onMapLoad={done}
/>);
});
it('renders without throwing', () => {
expect(wrapper).toExist();
});
});
I get the error:
Warning: Make sure you’ve put a <script> tag in your <head> element to load Google Maps JavaScript API v3. If you’re looking for built-in support to load it for you, use the “async/ScriptjsLoader” instead. See https://github.com/tomchentw/react-google-maps/pull/168
(Followed by the Mocha error:
“before all” hook failed Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure “done()” is called; if returning a Promise, ensure it resolves.
)
Therefore, ‘done’ is not being called, because of the first error preventing the map from being created.
Now, I’m using withScriptjs, and therefore google.maps should be loaded for me. I should not be getting the first error.
Note that the element <AsyncGoogleMap/> works perfectly in a real environment, but it does not work when testing.
Is there anything I have missed?
Issue Analytics
- State:
- Created 7 years ago
- Comments:19 (5 by maintainers)
@metr1ckzu
@tyewang wanna make a PR adding these to the
src/docs
😃 ?