]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test(link): add absolute alias active tests
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 7 Apr 2020 10:19:30 +0000 (12:19 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 7 Apr 2020 10:19:30 +0000 (12:19 +0200)
__tests__/RouterLink.spec.ts
__tests__/__snapshots__/RouterLink.spec.ts.snap

index fdb0c391f4e357c8276ba76ea22fe54d4db90e65..558a6f0765bb2f344bc0fb4913c19ce52e338abf 100644 (file)
@@ -171,6 +171,20 @@ const locations: Record<
       name: undefined,
     },
   },
+  childAsAbsolute: {
+    string: '/absolute-child',
+    normalized: {
+      fullPath: '/absolute-child',
+      path: '/absolute-child',
+      params: {},
+      meta: {},
+      query: {},
+      hash: '',
+      matched: [records.parent, records.child],
+      redirectedFrom: undefined,
+      name: undefined,
+    },
+  },
   childParentAlias: {
     string: '/p/child',
     normalized: {
@@ -394,8 +408,29 @@ describe('RouterLink', () => {
     )
   })
 
-  it.todo('parent is active if the child is an absolute path')
-  it.todo('alias parent is active if the child is an absolute path')
+  it('parent is active if the child is an absolute path', () => {
+    const { el } = factory(
+      locations.childAsAbsolute.normalized,
+      { to: locations.parent.string },
+      locations.parent.normalized
+    )
+    expect(el.querySelector('a')!.className).toContain('router-link-active')
+    expect(el.querySelector('a')!.className).not.toContain(
+      'router-link-exact-active'
+    )
+  })
+
+  it('alias parent is active if the child is an absolute path', () => {
+    const { el } = factory(
+      locations.childAsAbsolute.normalized,
+      { to: locations.parentAlias.string },
+      locations.parentAlias.normalized
+    )
+    expect(el.querySelector('a')!.className).toContain('router-link-active')
+    expect(el.querySelector('a')!.className).not.toContain(
+      'router-link-exact-active'
+    )
+  })
 
   it('alias parent is active when a child is active', () => {
     let { el } = factory(
@@ -515,17 +550,17 @@ describe('RouterLink', () => {
 
       router.resolve.mockReturnValueOnce(resolvedLocation)
       const { app, el } = mount(router as any, {
-        template: `<RouterLink :to="to" v-slot="data">
-        route: {{ JSON.stringify(data.route) }}
-        href: "{{ data.href }}"
-        isActive: "{{ data.isActive }}"
-        isExactActive: "{{ data.isExactActive }}"
+        template: `<RouterLink v-bind="propsData" v-slot="data">
+        <span>
+          route: {{ JSON.stringify(data.route) }}
+          href: "{{ data.href }}"
+          isActive: "{{ data.isActive }}"
+          isExactActive: "{{ data.isExactActive }}"
+        </span>
       </RouterLink>`,
         components: { RouterLink } as any,
         setup() {
-          const to = ref(propsData.to)
-
-          return { to }
+          return { propsData }
         },
       })
 
index 2052a2fcebaef95f5a9126334f72414e5ea92100..3d1327a29a2821b7010a8f8b7c0c7e16a8f952c2 100644 (file)
@@ -1,3 +1,3 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
-exports[`RouterLink v-slot provides information on v-slot 1`] = `"<a aria-current=\\"page\\" href=\\"/home\\" class=\\"router-link-active router-link-exact-active\\"> route: {\\"fullPath\\":\\"/home\\",\\"path\\":\\"/home\\",\\"params\\":{},\\"meta\\":{},\\"query\\":{},\\"hash\\":\\"\\",\\"matched\\":[{}]} href: \\"/home\\" isActive: \\"true\\" isExactActive: \\"true\\" </a>"`;
+exports[`RouterLink v-slot provides information on v-slot 1`] = `"<a aria-current=\\"page\\" href=\\"/home\\" class=\\"router-link-active router-link-exact-active\\"><span> route: {\\"fullPath\\":\\"/home\\",\\"path\\":\\"/home\\",\\"params\\":{},\\"meta\\":{},\\"query\\":{},\\"hash\\":\\"\\",\\"matched\\":[{}]} href: \\"/home\\" isActive: \\"true\\" isExactActive: \\"true\\" </span></a>"`;