]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: add useApi
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 14 Jan 2021 15:51:00 +0000 (16:51 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 14 Jan 2021 15:51:00 +0000 (16:51 +0100)
__tests__/useApi.spec.ts [new file with mode: 0644]

diff --git a/__tests__/useApi.spec.ts b/__tests__/useApi.spec.ts
new file mode 100644 (file)
index 0000000..e8e7be2
--- /dev/null
@@ -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: `<p>Query: {{ q }}</p>`,
+        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')
+  })
+})