Skip to content

Commit 06c4894

Browse files
author
Tom Chandler
committed
Fixed invalid Promise syntax in Plotly.plot
1 parent a762fe3 commit 06c4894

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

src/plot_api/plot_api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Plotly.plot = function(gd, data, layout, config) {
5959
Events.init(gd);
6060

6161
var okToPlot = Events.triggerHandler(gd, 'plotly_beforeplot', [data, layout, config]);
62-
if(okToPlot===false) return new Promise.reject();
62+
if(okToPlot===false) return Promise.reject();
6363

6464
// if there's no data or layout, and this isn't yet a plotly plot
6565
// container, log a warning to help plotly.js users debug
@@ -112,7 +112,7 @@ Plotly.plot = function(gd, data, layout, config) {
112112
// signal to drag handler that after everything else is done
113113
// we need to replot, because something has changed
114114
gd._replotPending = true;
115-
return new Promise.reject();
115+
return Promise.reject();
116116
} else {
117117
// we're going ahead with a replot now
118118
gd._replotPending = false;

test/jasmine/tests/plot_promise_test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var Plotly = require('@src/plotly');
2+
var Events = require('@src/lib/events');
23
var createGraphDiv = require('../assets/create_graph_div');
34
var destroyGraphDiv = require('../assets/destroy_graph_div');
45

@@ -29,6 +30,64 @@ describe('Plotly.___ methods', function() {
2930
});
3031
});
3132

33+
describe('Plotly.plot promise', function() {
34+
var gd,
35+
promise,
36+
promiseRejected = false;
37+
38+
beforeEach(function(done) {
39+
var data = [{ x: [1,2,3], y: [4,5,6] }];
40+
41+
gd = createGraphDiv();
42+
43+
Events.init(gd);
44+
45+
gd.on('plotly_beforeplot', function() {
46+
return false;
47+
});
48+
49+
promise = Plotly.plot(gd, data, {});
50+
51+
promise.then(null, function(){
52+
promiseRejected = true;
53+
done();
54+
});
55+
});
56+
57+
afterEach(destroyGraphDiv);
58+
59+
it('should be rejected when plotly_beforeplot event handlers return false', function() {
60+
expect(promiseRejected).toBe(true);
61+
});
62+
});
63+
64+
describe('Plotly.plot promise', function() {
65+
var gd,
66+
promise,
67+
promiseRejected = false;
68+
69+
beforeEach(function(done) {
70+
var data = [{ x: [1,2,3], y: [4,5,6] }];
71+
72+
gd = createGraphDiv();
73+
74+
gd._dragging = true;
75+
76+
promise = Plotly.plot(gd, data, {});
77+
78+
promise.then(null, function(){
79+
promiseRejected = true;
80+
done();
81+
});
82+
});
83+
84+
afterEach(destroyGraphDiv);
85+
86+
it('should reject the promise when graph is being dragged', function() {
87+
expect(promiseRejected).toBe(true);
88+
});
89+
});
90+
3291
describe('Plotly.redraw promise', function() {
3392
var promise,
3493
promiseGd;

0 commit comments

Comments
 (0)