diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index 9bc8a00b2..1884f070e 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -7,6 +7,22 @@ describe("Map", function () { }); describe("#remove", function () { + it("fires an unload event if loaded", function () { + var container = document.createElement('div'), + map = new L.Map(container).setView([0, 0], 0); + map.on('unload', spy); + map.remove(); + expect(spy).toHaveBeenCalled(); + }); + + it("fires no unload event if not loaded", function () { + var container = document.createElement('div'), + map = new L.Map(container); + map.on('unload', spy); + map.remove(); + expect(spy).not.toHaveBeenCalled(); + }); + it("undefines container._leaflet", function () { var container = document.createElement('div'), map = new L.Map(container); diff --git a/src/map/Map.js b/src/map/Map.js index a8368793e..669c57e6a 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -240,6 +240,9 @@ L.Map = L.Class.extend({ }, remove: function () { + if (this._loaded) { + this.fire('unload'); + } this._initEvents('off'); delete this._container._leaflet; return this;