Skip to content

Commit c198d19

Browse files
pieterddKjoep
andauthored
fix: ignore non-vue wrapper for auto-destroy (#1723)
Co-authored-by: Joeri Hendrickx <joeri.hendrickx@unleashed.be>
1 parent e1c2526 commit c198d19

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/test-utils/src/auto-destroy.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export function enableAutoDestroy(hook: (() => void) => void) {
2121
hook(() => {
2222
wrapperInstances.forEach((wrapper: Wrapper) => {
2323
// skip child wrappers created by wrapper.find()
24-
if (wrapper.selector) return
25-
26-
wrapper.destroy()
24+
if (wrapper.vm || wrapper.isFunctionalComponent) {
25+
wrapper.destroy()
26+
}
2727
})
2828

2929
wrapperInstances.length = 0

test/specs/wrapper.spec.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
22
import {
33
enableAutoDestroy,
4-
resetAutoDestroyState
4+
resetAutoDestroyState,
5+
createWrapper
56
} from 'packages/test-utils/src'
67

78
describeWithShallowAndMount('Wrapper', mountingMethod => {
@@ -51,5 +52,16 @@ describeWithShallowAndMount('Wrapper', mountingMethod => {
5152

5253
expect(() => enableAutoDestroy(noop)).toThrow()
5354
})
55+
56+
it('does not fail when non-Vue wrappers exist', async () => {
57+
let hookCallback
58+
enableAutoDestroy(callback => {
59+
hookCallback = callback
60+
})
61+
62+
createWrapper(document.createElement('div'))
63+
64+
expect(hookCallback).not.toThrow()
65+
})
5466
})
5567
})

0 commit comments

Comments
 (0)