Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 085b0c7

Browse filesBrowse files
committed
Add tests and clean up promise resolve/reject
1 parent c336dae commit 085b0c7
Copy full SHA for 085b0c7

File tree

Expand file treeCollapse file tree

2 files changed

+32
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+32
-3
lines changed

‎src/plots/plots.js

Copy file name to clipboardExpand all lines: src/plots/plots.js
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,11 @@ plots.redrawText = function(gd) {
233233

234234
// resize plot about the container size
235235
plots.resize = function(gd) {
236-
if (!gd || d3.select(gd).style('display') === 'none') return;
236+
return new Promise(function(resolve, reject) {
237237

238-
return new Promise(function(resolve) {
238+
if (!gd || d3.select(gd).style('display') === 'none'){
239+
reject(new Error('Resize must be passed a plot div element.'));
240+
}
239241

240242
if (gd._redrawTimer) clearTimeout(gd._redrawTimer);
241243

@@ -249,7 +251,7 @@ plots.resize = function(gd) {
249251

250252
Plotly.relayout(gd, { autosize: true });
251253
gd.changed = oldchanged;
252-
resolve();
254+
resolve(gd);
253255
}
254256
}, 100);
255257
});

‎test/jasmine/tests/plot_promise_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/plot_promise_test.js
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,4 +464,31 @@ describe('Plotly.___ methods', function() {
464464
});
465465
});
466466

467+
describe('Plotly.Plots.resize promise', function() {
468+
var initialDiv;
469+
470+
beforeEach(function(done) {
471+
var data = [{ x: [1,2,3], y: [4,5,6] }];
472+
473+
initialDiv = createGraphDiv();
474+
475+
Plotly.plot(initialDiv, data, {}).then(done);
476+
});
477+
478+
it('should return a resolved promise of the gd', function(done) {
479+
Plotly.Plots.resize(initialDiv).then(function(gd) {
480+
expect(gd).toBeDefined();
481+
expect(typeof gd).toBe('object');
482+
expect(gd.layout).toBeDefined();
483+
}).then(done);
484+
});
485+
486+
it('should return a rejected promise with no argument', function(done) {
487+
Plotly.Plots.resize().then(null, function(err) {
488+
expect(err).toBeDefined();
489+
expect(err.message).toBe('Resize must be passed a plot div element.');
490+
}).then(done);
491+
});
492+
});
493+
467494
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.