Skip to content

Commit

Permalink
added tests for 'withCredentials' option
Browse files Browse the repository at this point in the history
  • Loading branch information
luiscamachopt committed Oct 2, 2020
1 parent 064c24e commit ff3f46a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/Layers/RasterLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {}
};
Expand Down Expand Up @@ -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');
});
});
});
});
18 changes: 18 additions & 0 deletions spec/RequestSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit ff3f46a

Please sign in to comment.