expect(el.querySelector('a')!.getAttribute('href')).toBe('/home')
})
- // TODO: not sure why this breaks. We could take a look at @vue/test-runtime
- it.skip('can change the value', async () => {
+ it('can change the value', async () => {
const to = ref(locations.basic.string)
const { el, router } = factory(
START_LOCATION_NORMALIZED,
{ to },
locations.basic.normalized
)
- expect(el.innerHTML).toBe('<a class="" href="/home">a link</a>')
+ expect(el.querySelector('a')!.getAttribute('href')).toBe('/home')
router.resolve.mockReturnValueOnce(locations.foo.normalized)
to.value = locations.foo.string
await tick()
- expect(el.innerHTML).toBe('<a class="" href="/foo">a link</a>')
+ expect(el.querySelector('a')!.getAttribute('href')).toBe('/foo')
})
it('displays a link with an object with path prop', () => {
expect(el.querySelector('a')!.className).toContain('router-link-active')
})
+ it.todo('is active when a child is active')
+ it.todo('only the ')
+ it.todo('is not active if the parent is active')
+
it('can be exact-active', () => {
const { el } = factory(
locations.basic.normalized,
route: {{ JSON.stringify(data.route) }}
href: "{{ data.href }}"
isActive: "{{ data.isActive }}"
+ isExactActive: "{{ data.isExactActive }}"
</RouterLink>`,
components: { RouterLink } as any,
setup() {
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`RouterLink v-slot provides information on v-slot 1`] = `"<a class=\\"router-link-active router-link-exact-active\\" href=\\"/home\\"> route: {\\"fullPath\\":\\"/home\\",\\"path\\":\\"/home\\",\\"params\\":{},\\"meta\\":{},\\"query\\":{},\\"hash\\":\\"\\",\\"matched\\":[{}]} href: \\"/home\\" isActive: \\"true\\" </a>"`;
+exports[`RouterLink v-slot provides information on v-slot 1`] = `"<a class=\\"router-link-active router-link-exact-active\\" href=\\"/home\\"> route: {\\"fullPath\\":\\"/home\\",\\"path\\":\\"/home\\",\\"params\\":{},\\"meta\\":{},\\"query\\":{},\\"hash\\":\\"\\",\\"matched\\":[{}]} href: \\"/home\\" isActive: \\"true\\" isExactActive: \\"true\\" </a>"`;
return true
}
-// TODO: what should be accepted as arguments?
export function useLink(props: UseLinkOptions) {
const router = inject(routerKey)!
},
setup(props, { slots, attrs }) {
- const { route, isActive, isExactActive, href, navigate } = useLink(props)
+ const link = reactive(useLink(props))
const elClass = computed(() => ({
- 'router-link-active': isActive.value,
- 'router-link-exact-active': isExactActive.value,
+ 'router-link-active': link.isActive,
+ 'router-link-exact-active': link.isExactActive,
}))
- // TODO: exact active classes
- // TODO: handle replace prop
-
return () => {
return h(
'a',
{
class: elClass.value,
- onClick: navigate,
- href: href.value,
+ onClick: link.navigate,
+ href: link.href,
...attrs,
},
- slots.default(reactive({ route, href, isActive }))
+ slots.default(link)
)
}
},