]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test(router-link): add test regarding aria-current
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 5 Aug 2020 08:26:40 +0000 (10:26 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 5 Aug 2020 08:26:40 +0000 (10:26 +0200)
__tests__/RouterLink.spec.ts

index 5dbc426f0d489ea769f490cdb7c40baa4e7836fd..1b7606c4abdd277a31e6a34b056dc3dbe88b7dbc 100644 (file)
@@ -13,6 +13,7 @@ import { mount, createMockedRoute } from './mount'
 import { nextTick } from 'vue'
 import { RouteRecordNormalized } from '../src/matcher/types'
 import { routerKey } from '../src/injectionSymbols'
+import { tick } from './utils'
 
 const records = {
   home: {} as RouteRecordNormalized,
@@ -422,6 +423,27 @@ describe('RouterLink', () => {
     expect(wrapper.find('a')!.className).toContain('router-link-active')
   })
 
+  it('sets aria-current to page by default when exact active', async () => {
+    const { wrapper, route } = await factory(
+      locations.parent.normalized,
+      { to: locations.parent.string },
+      locations.parent.normalized
+    )
+    expect(wrapper.find('a')!.getAttribute('aria-current')).toBe('page')
+    route.set(locations.child.normalized)
+    await tick()
+    expect(wrapper.find('a')!.getAttribute('aria-current')).not.toBe('page')
+  })
+
+  it('can customize aria-current value', async () => {
+    const { wrapper } = await factory(
+      locations.basic.normalized,
+      { to: locations.basic.string, ariaCurrentValue: 'time' },
+      locations.basic.normalized
+    )
+    expect(wrapper.find('a')!.getAttribute('aria-current')).toBe('time')
+  })
+
   it('can customize active class', async () => {
     const { wrapper } = await factory(
       locations.basic.normalized,