Skip to content

fix: clear static tree for render #862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/create-instance/create-slot-vnodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ function createVNodes (
): Array<VNode> {
const el = compileToFunctions(`<div>${slotValue}</div>`)
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
}

Expand Down
18 changes: 12 additions & 6 deletions test/specs/mounting-options/attachToDocument.spec.js
Original file line number Diff line number Diff line change
@@ -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('<div><input /></div>')
const wrapper = mountingMethod(compiled, { attachToDocument: true })
it('attaches root node to document', () => {
const TestComponent = {
template: '<div class="attached"><input /></div>'
}
const wrapper = mountingMethod(TestComponent, {
attachToDocument: true
})
expect(document.querySelector('.attached')).to.not.equal(null)
expect(wrapper.options.attachedToDocument).to.equal(true)
})
})
Expand All @@ -16,8 +20,10 @@ describe('options.attachToDocument with renderToString', () => {
if (!isRunningJSDOM) {
return
}
const compiled = compileToFunctions('<div><input /></div>')
const fn = () => renderToString(compiled, { attachToDocument: true })
const TestComponent = {
template: '<div class="attached"><input /></div>'
}
const fn = () => renderToString(TestComponent, { attachToDocument: true })
const message =
'[vue-test-utils]: you cannot use attachToDocument with renderToString'
expect(fn)
Expand Down
16 changes: 15 additions & 1 deletion test/specs/mounting-options/slots.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,25 @@ describeWithMountingMethods('options.slots', mountingMethod => {
}
})

it('mounts component with default and named slots', () => {
const wrapper = mountingMethod(ComponentWithSlots, {
slots: {
default: '<span>hello</span>',
footer: '<p>world</p>'
}
})
const HTML = mountingMethod.name === 'renderToString'
? wrapper
: wrapper.html()
expect(HTML).to.contain('<span>hello</span>')
expect(HTML).to.contain('<p>world</p>')
})

it('mounts component with default and named text slot', () => {
const wrapper = mountingMethod(ComponentWithSlots, {
slots: {
default: 'hello,',
header: 'world'
footer: '<template>world</template>'
}
})
if (mountingMethod.name === 'renderToString') {
Expand Down
6 changes: 2 additions & 4 deletions test/specs/wrapper/destroy.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { compileToFunctions } from 'vue-template-compiler'
import { describeWithShallowAndMount } from '~resources/utils'
import sinon from 'sinon'

Expand All @@ -25,9 +24,8 @@ describeWithShallowAndMount('destroy', mountingMethod => {
expect(spy.calledOnce).to.equal(true)
})

it.skip('removes element from document.body', () => {
const compiled = compileToFunctions('<div></div>')
const wrapper = mountingMethod(compiled, { attachToDocument: true })
it('removes element from document.body', () => {
const wrapper = mountingMethod({ template: '<div />' }, { attachToDocument: true })
expect(wrapper.vm.$el.parentNode).to.equal(document.body)
wrapper.destroy()
expect(wrapper.vm.$el.parentNode).to.be.null
Expand Down