From: Eduardo San Martin Morote Date: Thu, 14 Jan 2021 15:51:00 +0000 (+0100) Subject: test: add useApi X-Git-Tag: v4.0.4~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ecb67ecc5476b347d831256dc112c362cf7eed3b;p=thirdparty%2Fvuejs%2Frouter.git test: add useApi --- diff --git a/__tests__/useApi.spec.ts b/__tests__/useApi.spec.ts new file mode 100644 index 00000000..e8e7be28 --- /dev/null +++ b/__tests__/useApi.spec.ts @@ -0,0 +1,42 @@ +/** + * @jest-environment jsdom + */ +import { mount } from '@vue/test-utils' +import { computed } from 'vue' +import { useRoute, createRouter, createMemoryHistory } from '../src' + +describe('use apis', () => { + it('unwraps useRoute()', async () => { + const router = createRouter({ + history: createMemoryHistory(), + routes: [ + { + path: '/:any(.*)', + component: {} as any, + }, + ], + }) + + const wrapper = mount( + { + template: `

Query: {{ q }}

`, + setup() { + const route = useRoute() + const q = computed(() => route.query.q) + + return { q } + }, + }, + { + global: { + plugins: [router], + }, + } + ) + + expect(wrapper.text()).toBe('Query:') + + await router.push('/?q=hi') + expect(wrapper.text()).toBe('Query: hi') + }) +})