File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
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
+ } )
You can’t perform that action at this time.
0 commit comments