@@ -358,7 +358,8 @@ async function factory(
358358 currentLocation : RouteLocationNormalized ,
359359 propsData : any ,
360360 resolvedLocation : RouteLocationResolved ,
361- slotTemplate : string = ''
361+ slotTemplate : string = '' ,
362+ component : any = RouterLink
362363) {
363364 const route = createMockedRoute ( currentLocation )
364365 const router = {
@@ -373,7 +374,7 @@ async function factory(
373374 }
374375 router . resolve . mockReturnValueOnce ( resolvedLocation )
375376
376- const wrapper = mount ( RouterLink as any , {
377+ const wrapper = mount ( component , {
377378 propsData,
378379 global : {
379380 provide : {
@@ -899,6 +900,32 @@ describe('RouterLink', () => {
899900 expect ( wrapper . html ( ) ) . not . toContain ( '</a>' )
900901 } )
901902
903+ // #2375
904+ it ( 'works with custom directive when custom=true' , async ( ) => {
905+ const Directive = ( el : HTMLElement ) => el . setAttribute ( 'data-test' , 'x' )
906+ const AppLink = defineComponent ( {
907+ template : `
908+ <router-link custom v-directive>
909+ <a></a>
910+ </router-link>
911+ ` ,
912+ components : { RouterLink } ,
913+ directives : { Directive } ,
914+ name : 'AppLink' ,
915+ } )
916+
917+ const { wrapper } = await factory (
918+ locations . basic . normalized ,
919+ { to : locations . basic . string } ,
920+ locations . basic . normalized ,
921+ undefined ,
922+ AppLink
923+ )
924+
925+ expect ( wrapper . element . tagName ) . toBe ( 'A' )
926+ expect ( wrapper . attributes ( 'data-test' ) ) . toBe ( 'x' )
927+ } )
928+
902929 describe ( 'Extending RouterLink' , ( ) => {
903930 const AppLink = defineComponent ( {
904931 template : `
@@ -932,59 +959,31 @@ describe('RouterLink', () => {
932959 } ,
933960 } )
934961
935- async function factoryCustom (
936- currentLocation : RouteLocationNormalized ,
937- propsData : any ,
938- resolvedLocation : RouteLocationResolved ,
939- slotTemplate : string = ''
940- ) {
941- const route = createMockedRoute ( currentLocation )
942- const router = {
943- history : createMemoryHistory ( ) ,
944- createHref ( to : RouteLocationNormalized ) : string {
945- return this . history . base + to . fullPath
946- } ,
947- options : { } as Partial < RouterOptions > ,
948- resolve : vi . fn ( ) ,
949- push : vi . fn ( ) . mockResolvedValue ( resolvedLocation ) ,
950- }
951- router . resolve . mockReturnValueOnce ( resolvedLocation )
952-
953- const wrapper = await mount ( AppLink as any , {
954- propsData,
955- global : {
956- provide : {
957- [ routerKey as any ] : router ,
958- ...route . provides ,
959- } ,
960- } ,
961- slots : { default : slotTemplate } ,
962- } )
963-
964- return { router, wrapper, route }
965- }
966-
967962 it ( 'can extend RouterLink with inactive class' , async ( ) => {
968- const { wrapper } = await factoryCustom (
963+ const { wrapper } = await factory (
969964 locations . basic . normalized ,
970965 {
971966 to : locations . basic . string ,
972967 inactiveClass : 'inactive' ,
973968 activeClass : 'active' ,
974969 } ,
975- locations . foo . normalized
970+ locations . foo . normalized ,
971+ undefined ,
972+ AppLink
976973 )
977974
978975 expect ( wrapper . find ( 'a' ) ! . classes ( ) ) . toEqual ( [ 'inactive' ] )
979976 } )
980977
981978 it ( 'can extend RouterLink with external link' , async ( ) => {
982- const { wrapper } = await factoryCustom (
979+ const { wrapper } = await factory (
983980 locations . basic . normalized ,
984981 {
985982 to : 'https://esm.dev' ,
986983 } ,
987- locations . foo . normalized
984+ locations . foo . normalized ,
985+ undefined ,
986+ AppLink
988987 )
989988
990989 expect ( wrapper . find ( 'a' ) ! . classes ( ) ) . toHaveLength ( 0 )
0 commit comments