@@ -461,6 +461,8 @@ describe('Plotly.___ methods', function() {
461
461
Plotly . plot ( initialDiv , data , { } ) . then ( done ) ;
462
462
} ) ;
463
463
464
+ afterEach ( destroyGraphDiv ) ;
465
+
464
466
it ( 'should return a resolved promise of the gd' , function ( done ) {
465
467
Plotly . Plots . resize ( initialDiv ) . then ( function ( gd ) {
466
468
expect ( gd ) . toBeDefined ( ) ;
@@ -469,14 +471,30 @@ describe('Plotly.___ methods', function() {
469
471
} ) . then ( done ) ;
470
472
} ) ;
471
473
472
- it ( 'should return a rejected promise with no argument' , function ( done ) {
473
- Plotly . Plots . resize ( ) . then ( function ( ) {
474
+ it ( 'should return a rejected promise if gd is hidden' , function ( done ) {
475
+ initialDiv . style . display = 'none' ;
476
+ Plotly . Plots . resize ( initialDiv ) . then ( function ( ) {
477
+ expect ( 1 ) . toBe ( 0 , 'We were supposed to get an error.' ) ;
478
+ } , function ( err ) {
479
+ expect ( err ) . toBeDefined ( ) ;
480
+ expect ( err . message ) . toBe ( 'Resize must be passed a displayed plot div element.' ) ;
481
+ } ) . then ( done ) ;
482
+ } ) ;
483
+
484
+ it ( 'should return a rejected promise if gd is detached from the DOM' , function ( done ) {
485
+ destroyGraphDiv ( ) ;
486
+ Plotly . Plots . resize ( initialDiv ) . then ( function ( ) {
474
487
expect ( 1 ) . toBe ( 0 , 'We were supposed to get an error.' ) ;
475
488
} , function ( err ) {
476
489
expect ( err ) . toBeDefined ( ) ;
477
490
expect ( err . message ) . toBe ( 'Resize must be passed a displayed plot div element.' ) ;
478
491
} ) . then ( done ) ;
479
492
} ) ;
493
+
494
+ it ( 'errors before even generating a promise if gd is not defined' , function ( ) {
495
+ expect ( function ( ) { Plotly . Plots . resize ( ) ; } )
496
+ . toThrow ( new Error ( 'DOM element provided is null or undefined' ) ) ;
497
+ } ) ;
480
498
} ) ;
481
499
482
500
} ) ;
0 commit comments