diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 9dc8c7b1e57..812b845e1a3 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -326,10 +326,6 @@ Plotly.plot = function(gd, data, layout, config) { // so that the caller doesn't care which route we took return Promise.all(gd._promises).then(function() { return gd; - }, function() { - // clear the promise queue if one of them got rejected - Lib.log('Clearing previous rejected promises from queue.'); - gd._promises = []; }); }; @@ -355,6 +351,12 @@ function getGraphDiv(gd) { return gd; // otherwise assume that gd is a DOM element } +// clear the promise queue if one of them got rejected +function clearPromiseQueue(gd) { + Lib.log('Clearing previous rejected promises from queue.'); + gd._promises = []; +} + function opaqueSetBackground(gd, bgColor) { gd._fullLayout._paperdiv.style('background', 'white'); Plotly.defaultConfig.setBackground(gd, bgColor); @@ -1536,6 +1538,7 @@ Plotly.moveTraces = function moveTraces(gd, currentIndices, newIndices) { // style files that want to specify cyclical default values). Plotly.restyle = function restyle(gd, astr, val, traces) { gd = getGraphDiv(gd); + clearPromiseQueue(gd); var i, fullLayout = gd._fullLayout, aobj = {}; @@ -2076,6 +2079,7 @@ function swapXYData(trace) { // allows setting multiple attributes simultaneously Plotly.relayout = function relayout(gd, astr, val) { gd = getGraphDiv(gd); + clearPromiseQueue(gd); if(gd.framework && gd.framework.isPolar) { return Promise.resolve(gd); diff --git a/test/jasmine/tests/mapbox_test.js b/test/jasmine/tests/mapbox_test.js index f8acf99dd69..1adad1f9f10 100644 --- a/test/jasmine/tests/mapbox_test.js +++ b/test/jasmine/tests/mapbox_test.js @@ -180,6 +180,8 @@ describe('mapbox credentials', function() { }); it('should throw error if token is invalid', function(done) { + var cnt = 0; + Plotly.plot(gd, [{ type: 'scattermapbox', lon: [10, 20, 30], @@ -187,11 +189,17 @@ describe('mapbox credentials', function() { }], {}, { mapboxAccessToken: dummyToken }).catch(function(err) { + cnt++; expect(err).toEqual(new Error(constants.mapOnErrorMsg)); - }).then(done); + }).then(function() { + expect(cnt).toEqual(1); + done(); + }); }); it('should use access token in mapbox layout options if present', function(done) { + var cnt = 0; + Plotly.plot(gd, [{ type: 'scattermapbox', lon: [10, 20, 30], @@ -202,7 +210,10 @@ describe('mapbox credentials', function() { } }, { mapboxAccessToken: dummyToken + }).catch(function() { + cnt++; }).then(function() { + expect(cnt).toEqual(0); expect(gd._fullLayout.mapbox.accesstoken).toEqual(MAPBOX_ACCESS_TOKEN); done(); }); @@ -493,21 +504,19 @@ describe('mapbox plots', function() { }); it('should be able to update the access token', function(done) { - var promise = Plotly.relayout(gd, 'mapbox.accesstoken', 'wont-work'); - - promise.catch(function(err) { + Plotly.relayout(gd, 'mapbox.accesstoken', 'wont-work').catch(function(err) { expect(gd._fullLayout.mapbox.accesstoken).toEqual('wont-work'); expect(err).toEqual(new Error(constants.mapOnErrorMsg)); - }); + expect(gd._promises.length).toEqual(1); - promise.then(function() { return Plotly.relayout(gd, 'mapbox.accesstoken', MAPBOX_ACCESS_TOKEN); }).then(function() { expect(gd._fullLayout.mapbox.accesstoken).toEqual(MAPBOX_ACCESS_TOKEN); - }).then(done); + expect(gd._promises.length).toEqual(0); + done(); + }); }); - it('should be able to update traces', function(done) { function assertDataPts(lengths) { var lines = getGeoJsonData(gd, 'lines'),