From 9529db0151b5b68a4b92ae879862366128d89964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Thu, 21 Jun 2012 20:15:53 +0200 Subject: [PATCH] throw an error if ol.map gets passed an unknown option --- src/api/map.js | 18 ++++++++++++++++++ test/spec/api/map.test.js | 20 +++++--------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/api/map.js b/src/api/map.js index e6aaf0cbfc..9d85fdde91 100644 --- a/src/api/map.js +++ b/src/api/map.js @@ -5,6 +5,7 @@ goog.require('ol.Map'); goog.require('ol.Projection'); goog.require('ol.loc'); goog.require('ol.projection'); +goog.require('ol.error'); /** @@ -49,21 +50,38 @@ ol.map = function(opt_arg) { } else if (goog.isObject(opt_arg)) { center = opt_arg['center']; + delete opt_arg['center']; zoom = opt_arg['zoom']; + delete opt_arg['zoom']; numZoomLevels = opt_arg['numZoomLevels']; + delete opt_arg['numZoomLevels']; projection = opt_arg['projection']; + delete opt_arg['projection']; userProjection = opt_arg['userProjection']; + delete opt_arg['userProjection']; maxExtent = opt_arg['maxExtent']; + delete opt_arg['maxExtent']; maxRes = opt_arg['maxRes']; + delete opt_arg['maxRes']; resolutions = opt_arg['resolutions']; + delete opt_arg['resolutions']; el = opt_arg['el']; + delete opt_arg['el']; layers = opt_arg['layers']; + delete opt_arg['layers']; controls = opt_arg['controls']; + delete opt_arg['controls']; + var k = goog.object.getAnyKey(opt_arg); + if (goog.isDef(k)) { + ol.error(k + ' is not a map option'); + } + } else { throw new Error('ol.map'); } } + var map = new ol.Map(); if (goog.isDef(el)) { diff --git a/test/spec/api/map.test.js b/test/spec/api/map.test.js index 1c16b6b94a..156fa08203 100644 --- a/test/spec/api/map.test.js +++ b/test/spec/api/map.test.js @@ -144,21 +144,11 @@ describe("ol.map", function() { }); it("provides feedback when you mess up", function() { - var map; - if (goog.DEBUG) { - // misspelling - expect(function() { - map = ol.map({ - centre: [1, 2] - }); - }).toThrow(new Error("Unsupported config property: centre")); - } else { - expect(function() { - map = ol.map({ - centre: [1, 2] - }); - }).not.toThrow(); - } + expect(function() { + var map = ol.map({ + centre: [1, 2] + }); + }).toThrow(); }); it("is destroyable", function() {