]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: add tests for custom global classes
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 30 Apr 2020 15:46:37 +0000 (17:46 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 30 Apr 2020 15:46:37 +0000 (17:46 +0200)
__tests__/RouterLink.spec.ts

index c020821537b8903df65b4ff0e6b82623def93594..5757779a402d3c67bbc378256b98eb10c10aacf9 100644 (file)
@@ -411,6 +411,64 @@ describe('RouterLink', () => {
     expect(wrapper.find('a')!.className).toContain('is-active')
   })
 
+  it('prop classes take over global', async () => {
+    const { wrapper, router } = await factory(
+      locations.basic.normalized,
+      // wrong location to set it later
+      {
+        to: locations.foo.string,
+        activeClass: 'is-active',
+        exactActiveClass: 'is-exact',
+      },
+      locations.foo.normalized
+    )
+    router.options.linkActiveClass = 'custom'
+    router.options.linkExactActiveClass = 'custom-exact'
+    // force render because options is not reactive
+    router.resolve.mockReturnValueOnce(locations.basic.normalized)
+    await wrapper.setProps({ to: locations.basic.string })
+    expect(wrapper.find('a')!.className).not.toContain('router-link-active')
+    expect(wrapper.find('a')!.className).not.toContain(
+      'router-link-exact-active'
+    )
+    expect(wrapper.find('a')!.className).not.toContain('custom')
+    expect(wrapper.find('a')!.className).not.toContain('custom-exact')
+    expect(wrapper.find('a')!.className).toContain('is-active')
+    expect(wrapper.find('a')!.className).toContain('is-exact')
+  })
+
+  it('can globally customize active class', async () => {
+    const { wrapper, router } = await factory(
+      locations.basic.normalized,
+      // wrong location to set it later
+      { to: locations.foo.string },
+      locations.foo.normalized
+    )
+    router.options.linkActiveClass = 'custom'
+    // force render because options is not reactive
+    router.resolve.mockReturnValueOnce(locations.basic.normalized)
+    await wrapper.setProps({ to: locations.basic.string })
+    expect(wrapper.find('a')!.className).not.toContain('router-link-active')
+    expect(wrapper.find('a')!.className).toContain('custom')
+  })
+
+  it('can globally customize exact active class', async () => {
+    const { wrapper, router } = await factory(
+      locations.basic.normalized,
+      // wrong location to set it later
+      { to: locations.foo.string },
+      locations.foo.normalized
+    )
+    router.options.linkExactActiveClass = 'custom'
+    // force render because options is not reactive
+    router.resolve.mockReturnValueOnce(locations.basic.normalized)
+    await wrapper.setProps({ to: locations.basic.string })
+    expect(wrapper.find('a')!.className).not.toContain(
+      'router-link-exact-active'
+    )
+    expect(wrapper.find('a')!.className).toContain('custom')
+  })
+
   it('can customize exact active class', async () => {
     const { wrapper } = await factory(
       locations.basic.normalized,