From ff3f46a7e4215eda478b5086d3c3e3bce9fcac83 Mon Sep 17 00:00:00 2001 From: Luis Camacho Date: Fri, 2 Oct 2020 17:21:09 +0100 Subject: [PATCH] added tests for 'withCredentials' option --- spec/Layers/RasterLayerSpec.js | 8 ++++++++ spec/RequestSpec.js | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/spec/Layers/RasterLayerSpec.js b/spec/Layers/RasterLayerSpec.js index 5fa2a568a..7570a849c 100644 --- a/spec/Layers/RasterLayerSpec.js +++ b/spec/Layers/RasterLayerSpec.js @@ -10,6 +10,7 @@ describe('L.esri.RasterLayer', function () { // Extend 'abstract' RasterLayer object and implement functionality required for tests var TestRasterLayer = L.esri.RasterLayer.extend({ initialize: function (options) { + L.setOptions(this, options); this.service = { metadata: function () {} }; @@ -91,6 +92,13 @@ describe('L.esri.RasterLayer', function () { expect(imageOverlay.off.calledWith('error', sinon.match.func, layer)).to.be.true; }); + + it('should send credentials', function () { + var layer = new TestRasterLayer({withCredentials: true}); + layer.addTo(map); + var imageOverlay = map.addLayer.getCall(1).args[0]; + expect(imageOverlay._image.crossOrigin).to.be.equal('use-credentials'); + }); }); }); }); diff --git a/spec/RequestSpec.js b/spec/RequestSpec.js index 78a336948..0df42e295 100644 --- a/spec/RequestSpec.js +++ b/spec/RequestSpec.js @@ -48,6 +48,24 @@ describe('L.esri request helpers', function () { requests[0].respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, JSON.stringify(sampleResponse)); }); + it('should be able to make a GET request with CORS and credentials', function (done) { + L.esri.get.CORS('http://services.arcgisonline.com/ArcGIS/rest/info', {}, function (error, response) { + expect(this.foo).to.equal('bar'); + expect(response).to.deep.equal(sampleResponse); + done(); + }, { + foo: 'bar', + options: { + withCredentials: true + } + }); + + expect(requests[0].url).to.equal('http://services.arcgisonline.com/ArcGIS/rest/info?f=json'); + expect(requests[0].method).to.equal('GET'); + expect(requests[0].withCredentials).to.equal(true); + requests[0].respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, JSON.stringify(sampleResponse)); + }); + it('should be able to make a GET request with JSONP', function (done) { var request = L.esri.get.JSONP('http://example.com/foo', {}, function (error, response) { expect(this.foo).to.equal('bar');