diff --git a/js/ui/map.js b/js/ui/map.js index be2cf24416f..83f92171673 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -139,6 +139,7 @@ class Map extends Camera { if (typeof options.container === 'string') { this._container = window.document.getElementById(options.container); + if (!this._container) throw new Error(`Container '${options.container}' not found.`); } else { this._container = options.container; } diff --git a/test/js/ui/map.test.js b/test/js/ui/map.test.js index c0d854d93dd..36492bdc4b8 100755 --- a/test/js/ui/map.test.js +++ b/test/js/ui/map.test.js @@ -56,6 +56,11 @@ test('Map', (t) => { t.ok(map.keyboard.isEnabled()); t.ok(map.scrollZoom.isEnabled()); t.ok(map.touchZoomRotate.isEnabled()); + t.throws(() => { + new Map({ + container: 'anElementIdWhichDoesNotExistInTheDocument' + }); + }, new Error("Container 'anElementIdWhichDoesNotExistInTheDocument' not found"), 'throws on invalid map container id'); t.end(); });