File tree 2 files changed +42
-1
lines changed
packages/gatsby-plugin-catch-links/src
2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -490,3 +490,41 @@ describe(`pathPrefix is handled if caught link to ${pathPrefix}/article navigate
490
490
clickElement . dispatchEvent ( clickEvent )
491
491
} )
492
492
} )
493
+
494
+ describe ( `navigation is routed through browser without SVGAnimatedString support` , ( ) => {
495
+ let hrefHandler
496
+ let eventDestroyer
497
+ let oldSVGAnimatedString = SVGAnimatedString
498
+
499
+ beforeAll ( ( ) => {
500
+ hrefHandler = jest . fn ( )
501
+ eventDestroyer = catchLinks . default ( window , { } , hrefHandler )
502
+ delete global . SVGAnimatedString
503
+ } )
504
+
505
+ afterAll ( ( ) => {
506
+ eventDestroyer ( )
507
+ global . SVGAnimatedString = oldSVGAnimatedString
508
+ } )
509
+
510
+ test ( `works without throwing an error` , ( ) => {
511
+ // create a click element to use for testing
512
+ const clickElement = document . createElement ( `a` )
513
+ clickElement . setAttribute ( `href` , `${ window . location . href } /article` )
514
+ document . body . appendChild ( clickElement )
515
+
516
+ // create the click event we'll be using for testing
517
+ const clickEvent = new MouseEvent ( `click` , {
518
+ bubbles : true ,
519
+ cancelable : true ,
520
+ view : window ,
521
+ } )
522
+
523
+ // and trigger click
524
+ clickElement . dispatchEvent ( clickEvent )
525
+
526
+ expect ( ( ) =>
527
+ catchLinks . routeThroughBrowserOrApp ( jest . fn ( ) ) ( clickEvent )
528
+ ) . not . toThrow ( )
529
+ } )
530
+ } )
Original file line number Diff line number Diff line change @@ -130,7 +130,10 @@ export const routeThroughBrowserOrApp = (
130
130
destination . href = clickedAnchor . href
131
131
}
132
132
133
- if ( clickedAnchor . href instanceof SVGAnimatedString ) {
133
+ if (
134
+ `SVGAnimatedString` in window &&
135
+ clickedAnchor . href instanceof SVGAnimatedString
136
+ ) {
134
137
destination . href = clickedAnchor . href . animVal
135
138
}
136
139
You can’t perform that action at this time.
0 commit comments