@@ -236,12 +236,22 @@ describe('frint-route-react › Link', () => {
236236 expect ( unsubscribeCount ) . to . equal ( 2 ) ;
237237 } ) ;
238238
239- it ( 'pushes new url to router, prevents default and doesn\'t stopPropagation when clicked', function ( ) {
239+ describe ( ' prevents default and doesn\'t stopPropagation when clicked ', function ( ) {
240240 const pushedUrls = [ ] ;
241+ const actualRouter = new MemoryRouterService ( ) ;
241242
242243 const router = {
243244 push ( url ) {
245+ actualRouter . push ( url ) ;
244246 pushedUrls . push ( url ) ;
247+ } ,
248+
249+ getHistory ( ) {
250+ return actualRouter . getHistory ( ) ;
251+ } ,
252+
253+ getMatch ( ...args ) {
254+ return actualRouter . getMatch . call ( actualRouter , ...args ) ;
245255 }
246256 } ;
247257
@@ -250,15 +260,32 @@ describe('frint-route-react › Link', () => {
250260 { context : createContextWithRouter ( router ) }
251261 ) ;
252262
253- let preventDefaultCalled = false ;
254- let stopPropagationCalled = false ;
255- wrapper . simulate ( 'click' , {
256- preventDefault ( ) { preventDefaultCalled = true ; } ,
257- stopPropagation ( ) { stopPropagationCalled = true ; }
263+ it ( 'and pushes new url to router when it doesn\'t match current url' , function ( ) {
264+ let preventDefaultCalled = 0 ;
265+ let stopPropagationCalled = 0 ;
266+ wrapper . simulate ( 'click' , {
267+ preventDefault ( ) { preventDefaultCalled += 1 ; } ,
268+ stopPropagation ( ) { stopPropagationCalled += 1 ; }
269+ } ) ;
270+
271+ expect ( pushedUrls ) . to . deep . equal ( [ '/about' ] ) ;
272+ expect ( preventDefaultCalled ) . to . equal ( 1 ) ;
273+ expect ( stopPropagationCalled ) . to . equal ( 0 ) ;
258274 } ) ;
259275
260- expect ( pushedUrls ) . to . deep . equal ( [ '/about' ] ) ;
261- expect ( preventDefaultCalled ) . to . be . true ;
262- expect ( stopPropagationCalled ) . to . be . false ;
276+
277+ it ( 'and doesn\'t push new url to router when it matches current url' , function ( ) {
278+ let preventDefaultCalled = 0 ;
279+ let stopPropagationCalled = 0 ;
280+ wrapper . simulate ( 'click' , {
281+ preventDefault ( ) { preventDefaultCalled += 1 ; } ,
282+ stopPropagation ( ) { stopPropagationCalled += 1 ; }
283+ } ) ;
284+
285+ // nothing new was added to the pushedUrls and that's the point
286+ expect ( pushedUrls ) . to . deep . equal ( [ '/about' ] ) ;
287+ expect ( preventDefaultCalled ) . to . equal ( 1 ) ;
288+ expect ( stopPropagationCalled ) . to . equal ( 0 ) ;
289+ } ) ;
263290 } ) ;
264291} ) ;
0 commit comments