Skip to content

Commit

Permalink
Use a more helpful error message when Map options.container doesn't e…
Browse files Browse the repository at this point in the history
…xist in the document (#3719)
  • Loading branch information
andrewharvey authored and Lucas Wojciechowski committed Dec 3, 2016
1 parent 6b0bb7e commit 2f5667d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions js/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions test/js/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down

0 comments on commit 2f5667d

Please sign in to comment.