File tree 2 files changed +28
-9
lines changed
2 files changed +28
-9
lines changed Original file line number Diff line number Diff line change 2
2
<button @click =" increment" >Click</button >
3
3
<div v-if =" count % 2 === 0" >Count: {{ count }}. Count is even.</div >
4
4
<div v-if =" count % 2 !== 0" >Count: {{ count }}. Count is odd.</div >
5
+
6
+ <div >PostID: {{ postId }}</div >
5
7
</template >
6
8
7
9
<script >
8
- import { computed } from " vue" ;
9
- import { useStore } from " vuex" ;
10
10
export default {
11
- setup () {
12
- const store = useStore ();
13
- const count = computed (() => store .state .count );
14
- const increment = () => {
15
- store .commit (" increment" );
16
- };
11
+ name: " App.vue" ,
12
+ computed: {
13
+ postId () {
14
+ return this .$route .params .postId ;
15
+ },
17
16
18
- return { count, increment };
17
+ count () {
18
+ return this .$store .state .count ;
19
+ },
20
+ },
21
+ methods: {
22
+ increment () {
23
+ this .$store .commit (" increment" );
24
+ },
19
25
},
20
26
};
21
27
</script >
Original file line number Diff line number Diff line change @@ -17,9 +17,17 @@ const createVuexStore = () => {
17
17
18
18
function factory ( ) {
19
19
const store = createVuexStore ( ) ;
20
+
20
21
return mount ( App , {
21
22
global : {
22
23
plugins : [ store ] ,
24
+ mocks : {
25
+ $route : {
26
+ params : {
27
+ postId : "1" ,
28
+ } ,
29
+ } ,
30
+ } ,
23
31
} ,
24
32
} ) ;
25
33
}
@@ -37,4 +45,9 @@ describe("App", () => {
37
45
await wrapper . find ( "button" ) . trigger ( "click" ) ;
38
46
expect ( wrapper . html ( ) ) . toContain ( "Count: 2. Count is even" ) ;
39
47
} ) ;
48
+
49
+ it ( "render router" , async ( ) => {
50
+ const wrapper = factory ( ) ;
51
+ expect ( wrapper . html ( ) ) . toContain ( "PostID: 1" ) ;
52
+ } ) ;
40
53
} ) ;
You can’t perform that action at this time.
0 commit comments