File tree 1 file changed +68
-0
lines changed
questions/208-tree-component
1 file changed +68
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { mount } from "@vue/test-utils"
2
+ import { describe , it , expect } from "vitest"
3
+
4
+ import App from "./App.vue"
5
+ import Tree from "./TreeComponent.vue"
6
+
7
+ describe ( "TreeComponent" , ( ) => {
8
+ it ( "should work" , async ( ) => {
9
+ const wrapper = mount ( App )
10
+ const wrapperTree = wrapper . findComponent ( Tree )
11
+ await wrapper . setProps ( {
12
+ data : [
13
+ {
14
+ key : "1" ,
15
+ title : "Parent 1" ,
16
+ children : [ {
17
+ key : "1-1" ,
18
+ title : "child 1" ,
19
+ } , {
20
+ key : "1-2" ,
21
+ title : "child 2" ,
22
+ children : [ {
23
+ key : "1-2-1" ,
24
+ title : "grandchild 1" ,
25
+ } , {
26
+ key : "1-2-2" ,
27
+ title : "grandchild 2" ,
28
+ } ] ,
29
+ } ] ,
30
+ } ,
31
+ {
32
+ key : "2" ,
33
+ title : "Parent 2" ,
34
+ children : [ {
35
+ key : "2-1" ,
36
+ title : "child 1" ,
37
+ children : [ {
38
+ key : "2-1-1" ,
39
+ title : "grandchild 1" ,
40
+ } , {
41
+ key : "2-1-2" ,
42
+ title : "grandchild 2" ,
43
+ } ] ,
44
+ } , {
45
+ key : "2-2" ,
46
+ title : "child 2" ,
47
+ } ] ,
48
+ } ,
49
+ {
50
+ key : "3" ,
51
+ title : "Parent 3" ,
52
+ children : [ {
53
+ key : "3-1" ,
54
+ title : "child 1" ,
55
+ children : [ {
56
+ key : "3-1-1" ,
57
+ title : "grandchild 1" ,
58
+ } , {
59
+ key : "3-1-2" ,
60
+ title : "grandchild 2" ,
61
+ } ] ,
62
+ } ] ,
63
+ } ,
64
+ ] ,
65
+ } )
66
+ expect ( wrapperTree . text ( ) ) . toMatchInlineSnapshot ( "\"Parent 1child 1child 2grandchild 1grandchild 2Parent 2child 1grandchild 1grandchild 2child 2Parent 3child 1grandchild 1grandchild 2\"" )
67
+ } )
68
+ } )
You can’t perform that action at this time.
0 commit comments