@@ -782,11 +782,15 @@ describe('src/cy/commands/actions/trigger', () => {
782782
783783 describe ( 'position argument' , ( ) => {
784784 it ( 'can trigger event on center by default' , ( done ) => {
785- const $button = cy . $$ ( '<button />' ) . css ( { width : 200 , height : 100 } ) . prependTo ( cy . $$ ( 'body' ) )
785+ const height = 100
786+ const $button = cy . $$ ( '<button />' ) . css ( { width : 200 , height } ) . prependTo ( cy . $$ ( 'body' ) )
786787
787788 const onMouseover = function ( e ) {
788789 expect ( e . clientX ) . to . equal ( 108 )
789- expect ( e . clientY ) . to . equal ( 50 )
790+
791+ // NOTE: in firefox, the element's top value can vary depending on how the AUT is scaled.
792+ // So we factor the top value into our assertion in a manner similar to the coordinate calculations.
793+ expect ( e . clientY ) . to . equal ( ( height / 2 ) + Math . floor ( e . target . getBoundingClientRect ( ) . top ) )
790794
791795 done ( )
792796 }
@@ -797,25 +801,30 @@ describe('src/cy/commands/actions/trigger', () => {
797801 } )
798802
799803 it ( 'can trigger event on center' , ( done ) => {
800- const $button = cy . $$ ( '<button />' ) . css ( { width : 200 , height : 100 } ) . prependTo ( cy . $$ ( 'body' ) )
804+ const height = 100
805+ const $button = cy . $$ ( '<button />' ) . css ( { width : 200 , height } ) . prependTo ( cy . $$ ( 'body' ) )
801806
802807 const onMouseover = function ( e ) {
803808 expect ( e . clientX ) . to . equal ( 108 )
804- expect ( e . clientY ) . to . equal ( 50 )
809+
810+ // NOTE: in firefox, the element's top value varies depending on how the AUT is scaled. So we factor
811+ // the top value into our assertion in a manner similar to the coordinate calculations.
812+ expect ( e . clientY ) . to . equal ( ( height / 2 ) + Math . floor ( e . target . getBoundingClientRect ( ) . top ) )
805813
806814 done ( )
807815 }
808816
809817 $button . on ( 'mouseover' , onMouseover )
810-
811818 cy . get ( 'button:first' ) . trigger ( 'mouseover' , 'center' )
812819 } )
813820
814821 it ( 'can trigger event on topLeft' , ( done ) => {
815822 const $button = cy . $$ ( '<button />' ) . css ( { width : 200 , height : 100 } ) . prependTo ( cy . $$ ( 'body' ) )
816823 const onMouseover = function ( e ) {
817824 expect ( e . clientX ) . to . equal ( 8 )
818- // NOTE: firefox leaves 1px on top of element on scroll, so add top offset
825+
826+ // NOTE: in firefox, the element's top value varies depending on how the AUT is scaled. So we factor
827+ // the top value into our assertion in a manner similar to the coordinate calculations.
819828 expect ( e . clientY ) . to . equal ( 0 + Math . ceil ( e . target . getBoundingClientRect ( ) . top ) )
820829
821830 done ( )
@@ -831,6 +840,9 @@ describe('src/cy/commands/actions/trigger', () => {
831840
832841 const onMouseover = function ( e ) {
833842 expect ( e . clientX ) . to . equal ( 207 )
843+
844+ // NOTE: in firefox, the element's top value varies depending on how the AUT is scaled. So we factor
845+ // the top value into our assertion in a manner similar to the coordinate calculations.
834846 expect ( e . clientY ) . to . equal ( 0 + Math . ceil ( e . target . getBoundingClientRect ( ) . top ) )
835847
836848 done ( )
@@ -842,11 +854,15 @@ describe('src/cy/commands/actions/trigger', () => {
842854 } )
843855
844856 it ( 'can trigger event on bottomLeft' , ( done ) => {
845- const $button = cy . $$ ( '<button />' ) . css ( { width : 200 , height : 100 } ) . prependTo ( cy . $$ ( 'body' ) )
857+ const height = 100
858+ const $button = cy . $$ ( '<button />' ) . css ( { width : 200 , height } ) . prependTo ( cy . $$ ( 'body' ) )
846859
847860 const onMouseover = function ( e ) {
848861 expect ( e . clientX ) . to . equal ( 8 )
849- expect ( e . clientY ) . to . equal ( 99 )
862+
863+ // NOTE: in firefox, the element's top value varies depending on how the AUT is scaled. So we factor
864+ // the top value into our assertion in a manner similar to the coordinate calculations.
865+ expect ( e . clientY ) . to . equal ( height + ( Math . floor ( e . target . getBoundingClientRect ( ) . top ) - 1 ) )
850866
851867 done ( )
852868 }
@@ -857,11 +873,15 @@ describe('src/cy/commands/actions/trigger', () => {
857873 } )
858874
859875 it ( 'can trigger event on bottomRight' , ( done ) => {
860- const $button = cy . $$ ( '<button />' ) . css ( { width : 200 , height : 100 } ) . prependTo ( cy . $$ ( 'body' ) )
876+ const height = 100
877+ const $button = cy . $$ ( '<button />' ) . css ( { width : 200 , height } ) . prependTo ( cy . $$ ( 'body' ) )
861878
862879 const onMouseover = function ( e ) {
863880 expect ( e . clientX ) . to . equal ( 207 )
864- expect ( e . clientY ) . to . equal ( 99 )
881+
882+ // NOTE: in firefox, the element's top value varies depending on how the AUT is scaled. So we factor
883+ // the top value into our assertion in a manner similar to the coordinate calculations.
884+ expect ( e . clientY ) . to . equal ( height + ( Math . floor ( e . target . getBoundingClientRect ( ) . top ) - 1 ) )
865885
866886 done ( )
867887 }
@@ -872,11 +892,15 @@ describe('src/cy/commands/actions/trigger', () => {
872892 } )
873893
874894 it ( 'can pass options along with position' , ( done ) => {
875- const $button = cy . $$ ( '<button />' ) . css ( { width : 200 , height : 100 } ) . prependTo ( cy . $$ ( 'body' ) )
895+ const height = 100
896+ const $button = cy . $$ ( '<button />' ) . css ( { width : 200 , height } ) . prependTo ( cy . $$ ( 'body' ) )
876897
877898 const onMouseover = function ( e ) {
878899 expect ( e . clientX ) . to . equal ( 207 )
879- expect ( e . clientY ) . to . equal ( 99 )
900+
901+ // NOTE: in firefox, the element's top value varies depending on how the AUT is scaled. So we factor
902+ // the top value into our assertion in a manner similar to the coordinate calculations.
903+ expect ( e . clientY ) . to . equal ( height + ( Math . floor ( e . target . getBoundingClientRect ( ) . top ) - 1 ) )
880904
881905 done ( )
882906 }
0 commit comments