diff --git a/packages/test-utils/src/auto-destroy.js b/packages/test-utils/src/auto-destroy.js index 8f9073077..15f27c500 100644 --- a/packages/test-utils/src/auto-destroy.js +++ b/packages/test-utils/src/auto-destroy.js @@ -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 diff --git a/test/specs/wrapper.spec.js b/test/specs/wrapper.spec.js index 95934dac3..b1855b196 100644 --- a/test/specs/wrapper.spec.js +++ b/test/specs/wrapper.spec.js @@ -1,7 +1,8 @@ import { describeWithShallowAndMount } from '~resources/utils' import { enableAutoDestroy, - resetAutoDestroyState + resetAutoDestroyState, + createWrapper } from 'packages/test-utils/src' describeWithShallowAndMount('Wrapper', mountingMethod => { @@ -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() + }) }) })