Add guard around mapDom event listener (#594)

Fixes an issue where, even if the end user has a proper google maps API
mock, the GoogleMaps component will throw an error when in a test
env.  ReactDOM.findDOMNode(this.googleMapDom_) returns `null`.

This commit wraps the subsequent addEventListener call in an `if` block,
ensuring that an empty DOM doesn't add complications to test suites
This commit is contained in:
Jeffrey Auriemma 2018-05-31 15:30:27 -04:00 committed by Michael Diego
parent d6576f226f
commit 99c3c847bb

View File

@ -249,11 +249,10 @@ export default class GoogleMap extends Component {
const mapDom = ReactDOM.findDOMNode(this.googleMapDom_);
// gmap can't prevent map drag if mousedown event already occured
// the only workaround I find is prevent mousedown native browser event
ReactDOM.findDOMNode(this.googleMapDom_).addEventListener(
'mousedown',
this._onMapMouseDownNative,
true
);
if (mapDom) {
mapDom.addEventListener('mousedown', this._onMapMouseDownNative, true);
}
window.addEventListener('mouseup', this._onChildMouseUp, false);