File tree Expand file tree Collapse file tree 2 files changed +28
-9
lines changed Expand file tree Collapse file tree 2 files changed +28
-9
lines changed Original file line number Diff line number Diff line change 22 <button @click =" increment" >Click</button >
33 <div v-if =" count % 2 === 0" >Count: {{ count }}. Count is even.</div >
44 <div v-if =" count % 2 !== 0" >Count: {{ count }}. Count is odd.</div >
5+
6+ <div >PostID: {{ postId }}</div >
57</template >
68
79<script >
8- import { computed } from " vue" ;
9- import { useStore } from " vuex" ;
1010export 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+ },
1716
18- return { count, increment };
17+ count () {
18+ return this .$store .state .count ;
19+ },
20+ },
21+ methods: {
22+ increment () {
23+ this .$store .commit (" increment" );
24+ },
1925 },
2026};
2127 </script >
Original file line number Diff line number Diff line change @@ -17,9 +17,17 @@ const createVuexStore = () => {
1717
1818function factory ( ) {
1919 const store = createVuexStore ( ) ;
20+
2021 return mount ( App , {
2122 global : {
2223 plugins : [ store ] ,
24+ mocks : {
25+ $route : {
26+ params : {
27+ postId : "1" ,
28+ } ,
29+ } ,
30+ } ,
2331 } ,
2432 } ) ;
2533}
@@ -37,4 +45,9 @@ describe("App", () => {
3745 await wrapper . find ( "button" ) . trigger ( "click" ) ;
3846 expect ( wrapper . html ( ) ) . toContain ( "Count: 2. Count is even" ) ;
3947 } ) ;
48+
49+ it ( "render router" , async ( ) => {
50+ const wrapper = factory ( ) ;
51+ expect ( wrapper . html ( ) ) . toContain ( "PostID: 1" ) ;
52+ } ) ;
4053} ) ;
You can’t perform that action at this time.
0 commit comments