diff --git a/packages/create-instance/create-slot-vnodes.js b/packages/create-instance/create-slot-vnodes.js index 56b29e889..dfa8edd44 100644 --- a/packages/create-instance/create-slot-vnodes.js +++ b/packages/create-instance/create-slot-vnodes.js @@ -8,13 +8,12 @@ function createVNodes ( ): Array { const el = compileToFunctions(`
${slotValue}
`) const _staticRenderFns = vm._renderProxy.$options.staticRenderFns - // version < 2.5 - if (!vm._renderProxy._staticTrees) { - vm._renderProxy._staticTrees = [] - } + const _staticTrees = vm._renderProxy._staticTrees + vm._renderProxy._staticTrees = [] vm._renderProxy.$options.staticRenderFns = el.staticRenderFns const vnode = el.render.call(vm._renderProxy, vm.$createElement) vm._renderProxy.$options.staticRenderFns = _staticRenderFns + vm._renderProxy._staticTrees = _staticTrees return vnode.children } diff --git a/test/specs/mounting-options/attachToDocument.spec.js b/test/specs/mounting-options/attachToDocument.spec.js index 3c12b5bf1..97083e0cf 100644 --- a/test/specs/mounting-options/attachToDocument.spec.js +++ b/test/specs/mounting-options/attachToDocument.spec.js @@ -1,11 +1,15 @@ -import { compileToFunctions } from 'vue-template-compiler' import { describeWithShallowAndMount, isRunningJSDOM } from '~resources/utils' import { renderToString } from '@vue/server-test-utils' describeWithShallowAndMount('options.attachToDocument', mountingMethod => { - it('returns VueWrapper with attachedToDocument set to true when passed attachToDocument in options', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled, { attachToDocument: true }) + it('attaches root node to document', () => { + const TestComponent = { + template: '
' + } + const wrapper = mountingMethod(TestComponent, { + attachToDocument: true + }) + expect(document.querySelector('.attached')).to.not.equal(null) expect(wrapper.options.attachedToDocument).to.equal(true) }) }) @@ -16,8 +20,10 @@ describe('options.attachToDocument with renderToString', () => { if (!isRunningJSDOM) { return } - const compiled = compileToFunctions('
') - const fn = () => renderToString(compiled, { attachToDocument: true }) + const TestComponent = { + template: '
' + } + const fn = () => renderToString(TestComponent, { attachToDocument: true }) const message = '[vue-test-utils]: you cannot use attachToDocument with renderToString' expect(fn) diff --git a/test/specs/mounting-options/slots.spec.js b/test/specs/mounting-options/slots.spec.js index 8c7656f67..4d2e1d3a1 100644 --- a/test/specs/mounting-options/slots.spec.js +++ b/test/specs/mounting-options/slots.spec.js @@ -223,11 +223,25 @@ describeWithMountingMethods('options.slots', mountingMethod => { } }) + it('mounts component with default and named slots', () => { + const wrapper = mountingMethod(ComponentWithSlots, { + slots: { + default: 'hello', + footer: '

world

' + } + }) + const HTML = mountingMethod.name === 'renderToString' + ? wrapper + : wrapper.html() + expect(HTML).to.contain('hello') + expect(HTML).to.contain('

world

') + }) + it('mounts component with default and named text slot', () => { const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: 'hello,', - header: 'world' + footer: '' } }) if (mountingMethod.name === 'renderToString') { diff --git a/test/specs/wrapper/destroy.spec.js b/test/specs/wrapper/destroy.spec.js index 4fe466a34..fd616e965 100644 --- a/test/specs/wrapper/destroy.spec.js +++ b/test/specs/wrapper/destroy.spec.js @@ -1,4 +1,3 @@ -import { compileToFunctions } from 'vue-template-compiler' import { describeWithShallowAndMount } from '~resources/utils' import sinon from 'sinon' @@ -25,9 +24,8 @@ describeWithShallowAndMount('destroy', mountingMethod => { expect(spy.calledOnce).to.equal(true) }) - it.skip('removes element from document.body', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled, { attachToDocument: true }) + it('removes element from document.body', () => { + const wrapper = mountingMethod({ template: '
' }, { attachToDocument: true }) expect(wrapper.vm.$el.parentNode).to.equal(document.body) wrapper.destroy() expect(wrapper.vm.$el.parentNode).to.be.null