Last active
March 6, 2019 20:15
-
-
Save nshimiye/2ac756133f8b1ec193bb90425b042536 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @WARNING this is incomplete | |
class YourComponent extends Component { | |
static contextType = GoogleMapContext; | |
componentDidMount() { | |
if (this.context.map) { | |
this.context.map.addListener('click', (e) => { // <= accessing map | |
this.context.map.setCenter(e.latLng); // <= accessing map | |
}); | |
} | |
} | |
render() { | |
return <div>Access to map instance using GoogleMapContext</div>; | |
} | |
} | |
describe('GoogleMapWithLoader', () => { | |
it('provides map instance to children components', () => { | |
const props = { | |
googleMapURL: '', | |
center: { lat: 0, lng: 0 }, | |
zoom: 1, | |
height: 100, | |
width: 100, | |
}; | |
const wrapper = mount(<GoogleMapWithLoader {...props}><YourComponent /></GoogleMapWithLoader>); | |
const instance = wrapper.find(YourComponent).instance(); | |
expect(instance.context.map).toBeInstanceOf(google.maps.Map); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment