From: Eduardo San Martin Morote Date: Fri, 24 Jan 2020 17:20:22 +0000 (+0100) Subject: refactor(link): useLink X-Git-Tag: v4.0.0-alpha.0~72 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fe4035837603dccb2c45b57d3ed9ac90ff6344bb;p=thirdparty%2Fvuejs%2Frouter.git refactor(link): useLink --- diff --git a/__tests__/RouterLink.spec.ts b/__tests__/RouterLink.spec.ts index 5200cbf5..79db8357 100644 --- a/__tests__/RouterLink.spec.ts +++ b/__tests__/RouterLink.spec.ts @@ -10,7 +10,7 @@ import { } from '../src/types' import { createMemoryHistory } from '../src' import { mount, tick } from './mount' -import { ref, markNonReactive } from 'vue' +import { ref, markNonReactive, isRef } from 'vue' const locations: Record< string, @@ -34,6 +34,20 @@ const locations: Record< name: undefined, }, }, + foo: { + string: '/foo', + // toResolve: { path: '/home', fullPath: '/home', undefined, query: {}, hash: '' }, + normalized: { + fullPath: '/foo', + path: '/foo', + params: {}, + meta: {}, + query: {}, + hash: '', + matched: [], + name: undefined, + }, + }, withQuery: { string: '/home?foo=a&bar=b', // toResolve: { path: '/home', fullPath: '/home', undefined, query: {}, hash: '' }, @@ -72,7 +86,7 @@ describe('RouterLink', () => { template: `a link`, components: { RouterLink } as any, setup() { - const to = ref(propsData.to) + const to = isRef(propsData.to) ? propsData.to : ref(propsData.to) return { to } }, @@ -90,6 +104,20 @@ describe('RouterLink', () => { expect(el.innerHTML).toBe('a link') }) + it('can change the value', async () => { + const to = ref(locations.basic.string) + const { el, router } = factory( + START_LOCATION_NORMALIZED, + { to }, + locations.basic.normalized + ) + expect(el.innerHTML).toBe('a link') + router.resolve.mockReturnValueOnce(locations.foo.normalized) + to.value = locations.foo.string + await tick() + expect(el.innerHTML).toBe('a link') + }) + it('displays a link with an object with path prop', () => { const { el } = factory( START_LOCATION_NORMALIZED, diff --git a/playground/index.html b/playground/index.html index 058156a1..1362b64c 100644 --- a/playground/index.html +++ b/playground/index.html @@ -8,6 +8,9 @@