From bfaf1fadd462a3597ca848a51a35457bae00123c Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 7 Apr 2020 12:19:30 +0200 Subject: [PATCH] test(link): add absolute alias active tests --- __tests__/RouterLink.spec.ts | 55 +++++++++++++++---- .../__snapshots__/RouterLink.spec.ts.snap | 2 +- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/__tests__/RouterLink.spec.ts b/__tests__/RouterLink.spec.ts index fdb0c391..558a6f07 100644 --- a/__tests__/RouterLink.spec.ts +++ b/__tests__/RouterLink.spec.ts @@ -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: ` - route: {{ JSON.stringify(data.route) }} - href: "{{ data.href }}" - isActive: "{{ data.isActive }}" - isExactActive: "{{ data.isExactActive }}" + template: ` + + route: {{ JSON.stringify(data.route) }} + href: "{{ data.href }}" + isActive: "{{ data.isActive }}" + isExactActive: "{{ data.isExactActive }}" + `, components: { RouterLink } as any, setup() { - const to = ref(propsData.to) - - return { to } + return { propsData } }, }) diff --git a/__tests__/__snapshots__/RouterLink.spec.ts.snap b/__tests__/__snapshots__/RouterLink.spec.ts.snap index 2052a2fc..3d1327a2 100644 --- a/__tests__/__snapshots__/RouterLink.spec.ts.snap +++ b/__tests__/__snapshots__/RouterLink.spec.ts.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`RouterLink v-slot provides information on v-slot 1`] = `" route: {\\"fullPath\\":\\"/home\\",\\"path\\":\\"/home\\",\\"params\\":{},\\"meta\\":{},\\"query\\":{},\\"hash\\":\\"\\",\\"matched\\":[{}]} href: \\"/home\\" isActive: \\"true\\" isExactActive: \\"true\\" "`; +exports[`RouterLink v-slot provides information on v-slot 1`] = `" route: {\\"fullPath\\":\\"/home\\",\\"path\\":\\"/home\\",\\"params\\":{},\\"meta\\":{},\\"query\\":{},\\"hash\\":\\"\\",\\"matched\\":[{}]} href: \\"/home\\" isActive: \\"true\\" isExactActive: \\"true\\" "`; -- 2.39.5