From 99c3c847bb2fb209fecdb6c69c1940a451ee26d1 Mon Sep 17 00:00:00 2001 From: Jeffrey Auriemma Date: Thu, 31 May 2018 15:30:27 -0400 Subject: [PATCH] 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 --- src/google_map.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/google_map.js b/src/google_map.js index af16a60..7bedecc 100644 --- a/src/google_map.js +++ b/src/google_map.js @@ -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);