@@ -539,6 +539,7 @@ describe('Test plot api', function() {
539539
540540 supplyAllDefaults ( gd ) ;
541541 Plots . doCalcdata ( gd ) ;
542+ gd . emit = function ( ) { } ;
542543 return gd ;
543544 }
544545
@@ -699,6 +700,7 @@ describe('Test plot api', function() {
699700 gd . calcdata = gd . _fullData . map ( function ( trace ) {
700701 return [ { x : 1 , y : 1 , trace : trace } ] ;
701702 } ) ;
703+ gd . emit = function ( ) { } ;
702704 }
703705
704706 it ( 'calls Scatter.arraysToCalcdata and Plots.style on scatter styling' , function ( ) {
@@ -2566,11 +2568,14 @@ describe('Test plot api', function() {
25662568 ] ;
25672569
25682570 var gd ;
2569- var plotCalls ;
2571+ var afterPlotCnt ;
25702572
25712573 beforeEach ( function ( ) {
25722574 gd = createGraphDiv ( ) ;
25732575
2576+ spyOn ( plotApi , 'plot' ) . and . callThrough ( ) ;
2577+ spyOn ( Registry , 'call' ) . and . callThrough ( ) ;
2578+
25742579 mockedMethods . forEach ( function ( m ) {
25752580 spyOn ( subroutines , m ) . and . callThrough ( ) ;
25762581 subroutines [ m ] . calls . reset ( ) ;
@@ -2584,13 +2589,14 @@ describe('Test plot api', function() {
25842589 afterEach ( destroyGraphDiv ) ;
25852590
25862591 function countPlots ( ) {
2587- plotCalls = 0 ;
2588-
2589- gd . on ( 'plotly_afterplot' , function ( ) { plotCalls ++ ; } ) ;
2592+ plotApi . plot . calls . reset ( ) ;
25902593 subroutines . layoutStyles . calls . reset ( ) ;
25912594 annotations . draw . calls . reset ( ) ;
25922595 annotations . drawOne . calls . reset ( ) ;
25932596 images . draw . calls . reset ( ) ;
2597+
2598+ afterPlotCnt = 0 ;
2599+ gd . on ( 'plotly_afterplot' , function ( ) { afterPlotCnt ++ ; } ) ;
25942600 }
25952601
25962602 function countCalls ( counts ) {
@@ -2602,8 +2608,14 @@ describe('Test plot api', function() {
26022608 subroutines [ m ] . calls . reset ( ) ;
26032609 } ) ;
26042610
2605- expect ( plotCalls ) . toBe ( counts . plot || 0 , 'calls to Plotly.plot' ) ;
2606- plotCalls = 0 ;
2611+ // calls to Plotly.plot via plot_api.js or Registry.call('plot')
2612+ var plotCalls = plotApi . plot . calls . count ( ) +
2613+ Registry . call . calls . all ( )
2614+ . filter ( function ( d ) { return d . args [ 0 ] === 'plot' ; } )
2615+ . length ;
2616+ expect ( plotCalls ) . toBe ( counts . plot || 0 , 'Plotly.plot calls' ) ;
2617+ plotApi . plot . calls . reset ( ) ;
2618+ Registry . call . calls . reset ( ) ;
26072619
26082620 // only consider annotation and image draw calls if we *don't* do a full plot.
26092621 if ( ! counts . plot ) {
@@ -2614,6 +2626,9 @@ describe('Test plot api', function() {
26142626 annotations . draw . calls . reset ( ) ;
26152627 annotations . drawOne . calls . reset ( ) ;
26162628 images . draw . calls . reset ( ) ;
2629+
2630+ expect ( afterPlotCnt ) . toBe ( 1 , 'plotly_afterplot should be called only once per edit' ) ;
2631+ afterPlotCnt = 0 ;
26172632 }
26182633
26192634 it ( 'can add / remove traces' , function ( done ) {
@@ -2654,14 +2669,14 @@ describe('Test plot api', function() {
26542669 . then ( function ( ) {
26552670 // didn't pick it up, as we modified in place!!!
26562671 expect ( d3 . selectAll ( '.point' ) . size ( ) ) . toBe ( 3 ) ;
2672+ countCalls ( { plot : 0 } ) ;
26572673
26582674 data [ 0 ] . y = [ 1 , 2 , 3 , 4 , 5 ] ;
26592675 return Plotly . react ( gd , data , layout ) ;
26602676 } )
26612677 . then ( function ( ) {
26622678 // new object, we picked it up!
26632679 expect ( d3 . selectAll ( '.point' ) . size ( ) ) . toBe ( 5 ) ;
2664-
26652680 countCalls ( { plot : 1 } ) ;
26662681 } )
26672682 . catch ( failTest )
@@ -2683,6 +2698,7 @@ describe('Test plot api', function() {
26832698 . then ( function ( ) {
26842699 // didn't pick it up, as we didn't modify datarevision
26852700 expect ( d3 . selectAll ( '.point' ) . size ( ) ) . toBe ( 3 ) ;
2701+ countCalls ( { plot : 0 } ) ;
26862702
26872703 data [ 0 ] . y . push ( 5 ) ;
26882704 layout . datarevision = 'bananas' ;
@@ -2869,7 +2885,7 @@ describe('Test plot api', function() {
28692885 sizex : 1 ,
28702886 sizey : 1
28712887 } ] ;
2872- Plotly . react ( gd , data , layout ) ;
2888+ return Plotly . react ( gd , data , layout ) ;
28732889 } )
28742890 . then ( function ( ) {
28752891 countCalls ( { imageDraw : 1 } ) ;
@@ -2883,7 +2899,7 @@ describe('Test plot api', function() {
28832899
28842900 layout . images [ 0 ] . y = 0.8 ;
28852901 layout . images [ 0 ] . sizey = 0.4 ;
2886- Plotly . react ( gd , data , layout ) ;
2902+ return Plotly . react ( gd , data , layout ) ;
28872903 } )
28882904 . then ( function ( ) {
28892905 countCalls ( { imageDraw : 1 } ) ;
0 commit comments