Skip to content

Commit

Permalink
test: add test case for vuejs#6687 + fix lingering comment node
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 authored and hefeng committed Jan 25, 2019
1 parent 3807e29 commit bc9e49c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/platforms/web/runtime/modules/transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ export function leave (vnode: VNodeWithData, rm: Function) {
}

const data = resolveTransition(vnode.data.transition)
if (isUndef(data)) {
if (isUndef(data) || el.nodeType !== 1) {
return rm()
}

/* istanbul ignore if */
if (isDef(el._leaveCb) || el.nodeType !== 1) {
if (isDef(el._leaveCb)) {
return
}

Expand Down
42 changes: 42 additions & 0 deletions test/unit/features/transition/transition.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,5 +1081,47 @@ if (!isIE9) {
}).then(done)
})
})

// #6687
it('transition on child components with empty root node', done => {
const vm = new Vue({
template: `
<div>
<transition mode="out-in">
<component class="test" :is="view"></component>
</transition>
</div>
`,
data: { view: 'one' },
components: {
'one': {
template: '<div v-if="false">one</div>'
},
'two': {
template: '<div>two</div>'
}
}
}).$mount(el)

// should not apply transition on initial render by default
expect(vm.$el.innerHTML).toBe('<!---->')
vm.view = 'two'
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe('<div class="test v-enter v-enter-active">two</div>')
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.children[0].className).toBe('test v-enter-active v-enter-to')
}).thenWaitFor(duration + buffer).then(() => {
expect(vm.$el.children[0].className).toBe('test')
vm.view = 'one'
}).then(() => {
// incoming comment node is appended instantly because it doesn't have
// data and therefore doesn't go through the transition module.
expect(vm.$el.innerHTML).toBe('<div class="test v-leave v-leave-active">two</div><!---->')
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.children[0].className).toBe('test v-leave-active v-leave-to')
}).thenWaitFor(duration + buffer).then(() => {
expect(vm.$el.innerHTML).toBe('<!---->')
}).then(done)
})
})
}

0 comments on commit bc9e49c

Please sign in to comment.