@@ -526,38 +526,36 @@ describe('Test colorbar:', function() {
526526 } ) ;
527527
528528 it ( 'creates the same colorbars attributes in newPlot and react' , function ( done ) {
529- var z = [ [ 1 , 10 ] , [ 100 , 1000 ] ] ;
530-
531- var expectedAttrs = [ ] ;
532- var actualAttrs = [ ] ;
533-
534- Plotly . newPlot ( gd , [ { type : 'contour' , z : z } ] )
535- . then ( function ( ) {
529+ function getCBFillAttributes ( ) {
530+ var attrs = [ ] ;
536531 var colorbars = d3 . select ( gd ) . selectAll ( '.colorbar' ) ;
537532 colorbars . selectAll ( '.cbfill' ) . each ( function ( ) {
538533 var attrsForElem = { } ;
539534 for ( var i = 0 ; i < this . attributes . length ; i ++ ) {
540535 var attr = this . attributes . item ( i ) ;
541536 attrsForElem [ attr . name ] = attr . value ;
542537 }
543- expectedAttrs . push ( attrsForElem ) ;
538+ attrs . push ( attrsForElem ) ;
544539 } ) ;
540+ return attrs ;
541+ }
542+
543+ var z = [ [ 1 , 10 ] , [ 100 , 1000 ] ] ;
544+
545+ var expectedAttrs ;
546+ var actualAttrs ;
547+
548+ Plotly . newPlot ( gd , [ { type : 'contour' , z : z } ] )
549+ . then ( function ( ) {
550+ expectedAttrs = getCBFillAttributes ( ) ;
545551
546552 return Plotly . newPlot ( gd , [ { type : 'heatmap' , z : z } ] )
547553 . then ( function ( ) {
548554 return Plotly . react ( gd , [ { type : 'contour' , z : z } ] ) ;
549555 } ) ;
550556 } )
551557 . then ( function ( ) {
552- var colorbars = d3 . select ( gd ) . selectAll ( '.colorbar' ) ;
553- colorbars . selectAll ( '.cbfill' ) . each ( function ( ) {
554- var attrsForElem = { } ;
555- for ( var i = 0 ; i < this . attributes . length ; i ++ ) {
556- var attr = this . attributes . item ( i ) ;
557- attrsForElem [ attr . name ] = attr . value ;
558- }
559- actualAttrs . push ( attrsForElem ) ;
560- } ) ;
558+ actualAttrs = getCBFillAttributes ( ) ;
561559 expect ( actualAttrs ) . toEqual ( expectedAttrs ) ;
562560 } )
563561 . catch ( failTest )
0 commit comments