Skip to content

Commit ecb67ec

Browse files
committed
test: add useApi
1 parent 245cc29 commit ecb67ec

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

__tests__/useApi.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
import { mount } from '@vue/test-utils'
5+
import { computed } from 'vue'
6+
import { useRoute, createRouter, createMemoryHistory } from '../src'
7+
8+
describe('use apis', () => {
9+
it('unwraps useRoute()', async () => {
10+
const router = createRouter({
11+
history: createMemoryHistory(),
12+
routes: [
13+
{
14+
path: '/:any(.*)',
15+
component: {} as any,
16+
},
17+
],
18+
})
19+
20+
const wrapper = mount(
21+
{
22+
template: `<p>Query: {{ q }}</p>`,
23+
setup() {
24+
const route = useRoute()
25+
const q = computed(() => route.query.q)
26+
27+
return { q }
28+
},
29+
},
30+
{
31+
global: {
32+
plugins: [router],
33+
},
34+
}
35+
)
36+
37+
expect(wrapper.text()).toBe('Query:')
38+
39+
await router.push('/?q=hi')
40+
expect(wrapper.text()).toBe('Query: hi')
41+
})
42+
})

0 commit comments

Comments
 (0)