From fa5f2875f9e7f97cbbb62b859d664808f46e2fde Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 28 Jul 2018 14:32:45 +0100 Subject: [PATCH 1/3] fix: clear static tree for render --- packages/create-instance/create-slot-vnodes.js | 7 +++---- test/specs/mounting-options/slots.spec.js | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) 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/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') { From 888014723ef4c34bcadb32044465a2baa3b19384 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 28 Jul 2018 14:48:49 +0100 Subject: [PATCH 2/3] test: unskip tests --- .../mounting-options/attachToDocument.spec.js | 18 ++++++++++++------ test/specs/wrapper/destroy.spec.js | 6 ++---- 2 files changed, 14 insertions(+), 10 deletions(-) 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/wrapper/destroy.spec.js b/test/specs/wrapper/destroy.spec.js index 4fe466a34..24ba1b087 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.only('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 From e56b59eb17c38cb7c694df04b04208e96158a8cb Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 28 Jul 2018 14:56:21 +0100 Subject: [PATCH 3/3] test: remove .only --- test/specs/wrapper/destroy.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/specs/wrapper/destroy.spec.js b/test/specs/wrapper/destroy.spec.js index 24ba1b087..fd616e965 100644 --- a/test/specs/wrapper/destroy.spec.js +++ b/test/specs/wrapper/destroy.spec.js @@ -24,7 +24,7 @@ describeWithShallowAndMount('destroy', mountingMethod => { expect(spy.calledOnce).to.equal(true) }) - it.only('removes element from document.body', () => { + it('removes element from document.body', () => { const wrapper = mountingMethod({ template: '
' }, { attachToDocument: true }) expect(wrapper.vm.$el.parentNode).to.equal(document.body) wrapper.destroy()