From: Eduardo San Martin Morote Date: Thu, 30 Apr 2020 15:46:37 +0000 (+0200) Subject: test: add tests for custom global classes X-Git-Tag: v4.0.0-alpha.10~40 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eba7ebec922440c24ccb3ddb6813af934d1aa2fa;p=thirdparty%2Fvuejs%2Frouter.git test: add tests for custom global classes --- diff --git a/__tests__/RouterLink.spec.ts b/__tests__/RouterLink.spec.ts index c0208215..5757779a 100644 --- a/__tests__/RouterLink.spec.ts +++ b/__tests__/RouterLink.spec.ts @@ -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,