File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,10 @@ export class VueWrapper<
107
107
return this . vm . $
108
108
}
109
109
110
+ exists ( ) {
111
+ return ! this . getCurrentComponent ( ) . isUnmounted
112
+ }
113
+
110
114
findAll < K extends keyof HTMLElementTagNameMap > (
111
115
selector : K
112
116
) : DOMWrapper < HTMLElementTagNameMap [ K ] > [ ]
Original file line number Diff line number Diff line change @@ -22,4 +22,31 @@ describe('exists', () => {
22
22
const wrapper = mount ( Component )
23
23
expect ( wrapper . find ( '#msg' ) . exists ( ) ) . toBe ( true )
24
24
} )
25
+
26
+ it ( 'returns false when component destroyed' , async ( ) => {
27
+ const ChildComponent = defineComponent ( {
28
+ render ( ) {
29
+ return h ( 'div' )
30
+ }
31
+ } )
32
+ const Component = defineComponent ( {
33
+ props : {
34
+ hide : {
35
+ type : Boolean ,
36
+ default : false
37
+ }
38
+ } ,
39
+ render ( ) {
40
+ if ( this . hide ) {
41
+ return h ( 'div' )
42
+ } else {
43
+ return h ( ChildComponent )
44
+ }
45
+ }
46
+ } )
47
+ const wrapper = mount ( Component )
48
+ const child = wrapper . findComponent ( ChildComponent )
49
+ await wrapper . setProps ( { hide : true } )
50
+ expect ( child . exists ( ) ) . toBe ( false )
51
+ } )
25
52
} )
You can’t perform that action at this time.
0 commit comments