@@ -101,6 +101,51 @@ describe('<Button>', () => {
101101 expect ( clickSpy ) . to . have . not . been . called ;
102102 } ) ;
103103
104+ // eslint-disable-next-line mocha/no-setup-in-describe
105+ [ '#' , '' ] . forEach ( ( href ) => {
106+ it ( `should prevent default on trivial href="${ href } " clicks` , ( ) => {
107+ const clickSpy = sinon . spy ( ) ;
108+
109+ const { getByText } = render (
110+ < div onClick = { clickSpy } >
111+ < Button href = { href } > Title</ Button >
112+ </ div > ,
113+ ) ;
114+
115+ const button = getByText ( 'Title' ) ;
116+
117+ expect ( button ) . to . exist ;
118+
119+ fireEvent . click ( button ) ;
120+
121+ expect ( clickSpy ) . to . have . been . called ;
122+ const event = clickSpy . getCall ( 0 ) . args [ 0 ] ;
123+
124+ expect ( event . defaultPrevented ) . to . equal ( true ) ;
125+ } ) ;
126+ } ) ;
127+
128+ it ( `should not prevent default on button clicks` , ( ) => {
129+ const clickSpy = sinon . spy ( ) ;
130+
131+ const { getByText } = render (
132+ < div onClick = { clickSpy } >
133+ < Button > Title</ Button >
134+ </ div > ,
135+ ) ;
136+
137+ const button = getByText ( 'Title' ) ;
138+
139+ expect ( button ) . to . exist ;
140+
141+ fireEvent . click ( button ) ;
142+
143+ expect ( clickSpy ) . to . have . been . called ;
144+ const event = clickSpy . getCall ( 0 ) . args [ 0 ] ;
145+
146+ expect ( event . defaultPrevented ) . to . equal ( false ) ;
147+ } ) ;
148+
104149 it ( 'Should be disabled link' , ( ) => {
105150 const clickSpy = sinon . spy ( ) ;
106151
0 commit comments