11import { init } from "$lib/init.js" ;
22import { location } from "$lib/core/Location.js" ;
3- import { describe , test , expect , beforeAll , afterAll , beforeEach , vi } from "vitest" ;
3+ import { describe , test , expect , beforeAll , afterAll , beforeEach , vi , afterEach } from "vitest" ;
44import { render , fireEvent } from "@testing-library/svelte" ;
55import Link from "./Link.svelte" ;
6- import { createRouterTestSetup , createTestSnippet , ROUTING_UNIVERSES } from "../../testing/test-utils.js" ;
6+ import { createRouterTestSetup , createTestSnippet , ROUTING_UNIVERSES , ALL_HASHES } from "../../testing/test-utils.js" ;
77import { flushSync } from "svelte" ;
8+ import { resetRoutingOptions , setRoutingOptions } from "$lib/core/options.js" ;
9+ import type { ExtendedRoutingOptions } from "$lib/types.js" ;
810
911function basicLinkTests ( setup : ReturnType < typeof createRouterTestSetup > ) {
1012 const linkText = "Test Link" ;
@@ -636,6 +638,61 @@ function reactivityTests(setup: ReturnType<typeof createRouterTestSetup>) {
636638 } ) ;
637639}
638640
641+ describe ( "Routing Mode Assertions" , ( ) => {
642+ const linkText = "Test Link" ;
643+ const content = createTestSnippet ( linkText ) ;
644+ let cleanup : ( ) => void ;
645+
646+ beforeAll ( ( ) => {
647+ cleanup = init ( ) ;
648+ } ) ;
649+
650+ afterEach ( ( ) => {
651+ resetRoutingOptions ( ) ;
652+ } ) ;
653+
654+ afterAll ( ( ) => {
655+ cleanup ( ) ;
656+ } ) ;
657+
658+ test . each < {
659+ options : Partial < ExtendedRoutingOptions > ;
660+ hash : typeof ALL_HASHES [ keyof typeof ALL_HASHES ] ;
661+ description : string ;
662+ } > ( [
663+ {
664+ options : { disallowHashRouting : true } ,
665+ hash : ALL_HASHES . single ,
666+ description : 'hash routing is disallowed'
667+ } ,
668+ {
669+ options : { disallowMultiHashRouting : true } ,
670+ hash : ALL_HASHES . multi ,
671+ description : 'multi-hash routing is disallowed'
672+ } ,
673+ {
674+ options : { disallowPathRouting : true } ,
675+ hash : ALL_HASHES . path ,
676+ description : 'path routing is disallowed'
677+ }
678+ ] ) ( "Should throw error when $description and hash=$hash ." , ( { options, hash } ) => {
679+ // Arrange
680+ setRoutingOptions ( options ) ;
681+
682+ // Act & Assert
683+ expect ( ( ) => {
684+ render ( Link , {
685+ props : {
686+ href : "/test" ,
687+ hash,
688+ children : content
689+ } ,
690+ } ) ;
691+ } ) . toThrow ( ) ;
692+ } ) ;
693+ } ) ;
694+
695+
639696ROUTING_UNIVERSES . forEach ( ru => {
640697 describe ( `Link - ${ ru . text } ` , ( ) => {
641698 const setup = createRouterTestSetup ( ru . hash ) ;
@@ -649,7 +706,7 @@ ROUTING_UNIVERSES.forEach(ru => {
649706 } ) ;
650707
651708 afterAll ( ( ) => {
652- cleanup ( ) ;
709+ cleanup ?. ( ) ;
653710 } ) ;
654711
655712 describe ( "Basic Link Functionality" , ( ) => {
0 commit comments