diff --git a/spec/runner.html b/spec/runner.html index 1520f191d..14ed94ee6 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -7,7 +7,11 @@ - + + + @@ -20,6 +24,8 @@ + + diff --git a/spec/suites/envSpec.js b/spec/suites/envSpec.js new file mode 100644 index 000000000..29c2b1c59 --- /dev/null +++ b/spec/suites/envSpec.js @@ -0,0 +1,15 @@ +describe('L#noConflict', function() { + it('should restore the previous L value and return Leaflet namespace', function(){ + + expect(L.version).toBeDefined(); + + var L2 = L.noConflict(); + + expect(L).toEqual('test'); + expect(L2.version).toBeDefined(); + + this.after(function() { + window.L = L2; + }); + }); +}); \ No newline at end of file diff --git a/src/env.js b/src/env.js index 1215f5640..676a2b2f5 100644 --- a/src/env.js +++ b/src/env.js @@ -1,11 +1,16 @@ /* - * Leaflet namespace config, allows using any global variable instead of L + * Leaflet namespace config, allows using any global variable instead of L & restoring the original value */ -var originalL = window.L, - L = {}; - -L.noConflict = function() { - window.L = originalL; - return this; -}; \ No newline at end of file +(function() { + var originalL = window.L; + + L = { + version: '0.0.1' + }; + + L.noConflict = function() { + window.L = originalL; + return this; + }; +})(); \ No newline at end of file