Skip to content

Commit 2b1ef0a

Browse files
authored
feat(wrapper): allow destroy() method to work with functional components
Currently when calling `wrapper.destroy()`, only non-functional components are removed from the DOM. This PR allows functional components to be removed from the DOM as well.
1 parent b5b511e commit 2b1ef0a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/test-utils/src/wrapper.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,19 @@ export default class Wrapper implements BaseWrapper {
124124
* Calls destroy on vm
125125
*/
126126
destroy(): void {
127-
if (!this.isVueInstance()) {
128-
throwError(`wrapper.destroy() can only be called on a Vue instance`)
127+
if (!this.isVueInstance() || !this.isFunctionalComponent) {
128+
throwError(`wrapper.destroy() can only be called on a Vue instance or functional component`)
129129
}
130130

131131
if (this.element.parentNode) {
132132
this.element.parentNode.removeChild(this.element)
133133
}
134-
// $FlowIgnore
135-
this.vm.$destroy()
136-
throwIfInstancesThrew(this.vm)
134+
135+
if (!this.isFunctionalComponent) {
136+
// $FlowIgnore
137+
this.vm.$destroy()
138+
throwIfInstancesThrew(this.vm)
139+
}
137140
}
138141

139142
/**

0 commit comments

Comments
 (0)