@@ -516,23 +516,31 @@ describe('Clerk singleton', () => {
516
516
517
517
describe ( '.navigate(to)' , ( ) => {
518
518
let sut : Clerk ;
519
+ let logSpy ;
519
520
520
521
beforeEach ( ( ) => {
522
+ logSpy = jest . spyOn ( console , 'log' ) ;
521
523
sut = new Clerk ( productionPublishableKey ) ;
522
524
} ) ;
523
525
526
+ afterEach ( ( ) => {
527
+ logSpy ?. mockRestore ( ) ;
528
+ } ) ;
529
+
524
530
it ( 'uses window location if a custom navigate is not defined' , async ( ) => {
525
531
await sut . load ( ) ;
526
532
const toUrl = 'http://test.host/' ;
527
533
await sut . navigate ( toUrl ) ;
528
534
expect ( mockHref ) . toHaveBeenCalledWith ( toUrl ) ;
535
+ expect ( logSpy ) . not . toBeCalled ( ) ;
529
536
} ) ;
530
537
531
538
it ( 'uses window location if a custom navigate is defined but destination has different origin' , async ( ) => {
532
539
await sut . load ( { routerPush : mockNavigate } ) ;
533
540
const toUrl = 'https://www.origindifferent.com/' ;
534
541
await sut . navigate ( toUrl ) ;
535
542
expect ( mockHref ) . toHaveBeenCalledWith ( toUrl ) ;
543
+ expect ( logSpy ) . not . toBeCalled ( ) ;
536
544
} ) ;
537
545
538
546
it ( 'wraps custom navigate method in a promise if provided and it sync' , async ( ) => {
@@ -542,6 +550,29 @@ describe('Clerk singleton', () => {
542
550
expect ( res . then ) . toBeDefined ( ) ;
543
551
expect ( mockHref ) . not . toHaveBeenCalled ( ) ;
544
552
expect ( mockNavigate ) . toHaveBeenCalledWith ( '/path#hash' ) ;
553
+ expect ( logSpy ) . not . toBeCalled ( ) ;
554
+ } ) ;
555
+
556
+ it ( 'logs navigation external navigation when routerDebug is enabled' , async ( ) => {
557
+ await sut . load ( { routerDebug : true } ) ;
558
+ const toUrl = 'http://test.host/' ;
559
+ await sut . navigate ( toUrl ) ;
560
+ expect ( mockHref ) . toHaveBeenCalledWith ( toUrl ) ;
561
+
562
+ expect ( logSpy ) . toBeCalledTimes ( 1 ) ;
563
+ expect ( logSpy ) . toBeCalledWith ( `Clerk is navigating to: ${ toUrl } ` ) ;
564
+ } ) ;
565
+
566
+ it ( 'logs navigation custom navigation when routerDebug is enabled' , async ( ) => {
567
+ await sut . load ( { routerPush : mockNavigate , routerDebug : true } ) ;
568
+ const toUrl = 'http://test.host/path#hash' ;
569
+ const res = sut . navigate ( toUrl ) ;
570
+ expect ( res . then ) . toBeDefined ( ) ;
571
+ expect ( mockHref ) . not . toHaveBeenCalled ( ) ;
572
+ expect ( mockNavigate ) . toHaveBeenCalledWith ( '/path#hash' ) ;
573
+
574
+ expect ( logSpy ) . toBeCalledTimes ( 1 ) ;
575
+ expect ( logSpy ) . toBeCalledWith ( `Clerk is navigating to: ${ toUrl } ` ) ;
545
576
} ) ;
546
577
} ) ;
547
578
0 commit comments