@@ -942,7 +942,6 @@ describe('hover info', function() {
942942 describe ( 'histogram hover info' , function ( ) {
943943 it ( 'shows the data range when bins have multiple values' , function ( done ) {
944944 var gd = createGraphDiv ( ) ;
945- var pts ;
946945
947946 Plotly . plot ( gd , [ {
948947 x : [ 0 , 2 , 3 , 4 , 5 , 6 , 7 ] ,
@@ -954,18 +953,15 @@ describe('hover info', function() {
954953 margin : { l : 0 , t : 0 , r : 0 , b : 0 }
955954 } )
956955 . then ( function ( ) {
957- gd . on ( 'plotly_hover' , function ( e ) { pts = e . points ; } ) ;
956+ var pts = null ;
957+ gd . once ( 'plotly_hover' , function ( e ) { pts = e . points ; } ) ;
958958
959959 _hoverNatural ( gd , 250 , 200 ) ;
960- assertHoverLabelContent ( {
961- nums : '3' ,
962- axis : '3 - 5'
963- } ) ;
964- } )
965- . then ( function ( ) {
960+ assertHoverLabelContent ( { nums : '3' , axis : '3 - 5' } ) ;
961+ if ( pts === null ) fail ( 'no hover evt triggered' ) ;
966962 expect ( pts . length ) . toBe ( 1 ) ;
967- var pt = pts [ 0 ] ;
968963
964+ var pt = pts [ 0 ] ;
969965 expect ( pt . curveNumber ) . toBe ( 0 ) ;
970966 expect ( pt . binNumber ) . toBe ( 1 ) ;
971967 expect ( pt . pointNumbers ) . toEqual ( [ 2 , 3 , 4 ] ) ;
@@ -976,6 +972,32 @@ describe('hover info', function() {
976972 expect ( pt . xaxis ) . toBe ( gd . _fullLayout . xaxis ) ;
977973 expect ( pt . yaxis ) . toBe ( gd . _fullLayout . yaxis ) ;
978974 } )
975+ . then ( function ( ) {
976+ var pts = null ;
977+ gd . once ( 'plotly_hover' , function ( e ) { pts = e . points ; } ) ;
978+
979+ _hoverNatural ( gd , 250 , 200 ) ;
980+ expect ( pts ) . toBe ( null , 'should not emit hover event on same pt' ) ;
981+ } )
982+ . then ( function ( ) {
983+ var pts = null ;
984+ gd . once ( 'plotly_hover' , function ( e ) { pts = e . points ; } ) ;
985+
986+ _hoverNatural ( gd , 350 , 200 ) ;
987+ assertHoverLabelContent ( { nums : '2' , axis : '6 - 8' } ) ;
988+ expect ( pts . length ) . toBe ( 1 ) ;
989+
990+ var pt = pts [ 0 ] ;
991+ expect ( pt . curveNumber ) . toBe ( 0 ) ;
992+ expect ( pt . binNumber ) . toBe ( 2 ) ;
993+ expect ( pt . pointNumbers ) . toEqual ( [ 5 , 6 ] ) ;
994+ expect ( pt . x ) . toBe ( 7 ) ;
995+ expect ( pt . y ) . toBe ( 2 ) ;
996+ expect ( pt . data ) . toBe ( gd . data [ 0 ] ) ;
997+ expect ( pt . fullData ) . toBe ( gd . _fullData [ 0 ] ) ;
998+ expect ( pt . xaxis ) . toBe ( gd . _fullLayout . xaxis ) ;
999+ expect ( pt . yaxis ) . toBe ( gd . _fullLayout . yaxis ) ;
1000+ } )
9791001 . catch ( failTest )
9801002 . then ( done ) ;
9811003 } ) ;
0 commit comments