Skip to content

Commit

Permalink
fix: ignore non-vue wrapper for auto-destroy (#1723)
Browse files Browse the repository at this point in the history
Co-authored-by: Joeri Hendrickx <joeri.hendrickx@unleashed.be>
  • Loading branch information
pieterdd and Kjoep committed Oct 31, 2020
1 parent e1c2526 commit c198d19
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/test-utils/src/auto-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export function enableAutoDestroy(hook: (() => void) => void) {
hook(() => {
wrapperInstances.forEach((wrapper: Wrapper) => {
// skip child wrappers created by wrapper.find()
if (wrapper.selector) return

wrapper.destroy()
if (wrapper.vm || wrapper.isFunctionalComponent) {
wrapper.destroy()
}
})

wrapperInstances.length = 0
Expand Down
14 changes: 13 additions & 1 deletion test/specs/wrapper.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { describeWithShallowAndMount } from '~resources/utils'
import {
enableAutoDestroy,
resetAutoDestroyState
resetAutoDestroyState,
createWrapper
} from 'packages/test-utils/src'

describeWithShallowAndMount('Wrapper', mountingMethod => {
Expand Down Expand Up @@ -51,5 +52,16 @@ describeWithShallowAndMount('Wrapper', mountingMethod => {

expect(() => enableAutoDestroy(noop)).toThrow()
})

it('does not fail when non-Vue wrappers exist', async () => {
let hookCallback
enableAutoDestroy(callback => {
hookCallback = callback
})

createWrapper(document.createElement('div'))

expect(hookCallback).not.toThrow()
})
})
})

0 comments on commit c198d19

Please sign in to comment.