Skip to content

Commit fd4d7c9

Browse files
committed
feat(transition): add TransitionGroupStub
1 parent bacc1fd commit fd4d7c9

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

src/components/TransitionGroupStub.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @flow
2+
3+
export default {
4+
render (h: Function) {
5+
const tag: string = this.tag || this.$vnode.data.tag || 'span'
6+
const children: Array<VNode> = this.$slots.default || []
7+
8+
return h(tag, null, children)
9+
}
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<transition-group>
3+
<div>{{a}}</div>
4+
<div></div>
5+
</transition-group>
6+
</template>
7+
8+
<script>
9+
export default{
10+
name: 'component-with-transition',
11+
data: () => ({
12+
a: 'a'
13+
})
14+
}
15+
</script>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import ComponentWithTransitionGroup from '~resources/components/component-with-transition-group.vue'
2+
import TransitionGroupStub from '~src/components/TransitionGroupStub'
3+
import mount from '~src/mount'
4+
5+
describe('TransitionGroupStub', () => {
6+
it('update synchronously when used as stubs for Transition', () => {
7+
const wrapper = mount(ComponentWithTransitionGroup, {
8+
stubs: {
9+
'transition-group': TransitionGroupStub
10+
}
11+
})
12+
expect(wrapper.text()).contains('a')
13+
wrapper.setData({ a: 'b' })
14+
expect(wrapper.text()).contains('b')
15+
})
16+
17+
// it('logs error when has multiple children', () => {
18+
// const TestComponent = {
19+
// template: `
20+
// <transition><div /><div /></transition>
21+
// `
22+
// }
23+
// const msg = '[vue-test-utils]: <transition> can only be used on a single element. Use <transition-group> for lists.'
24+
// const error = sinon.stub(console, 'error')
25+
// mount(TestComponent, {
26+
// stubs: {
27+
// 'transition': TransitionStub
28+
// }
29+
// })
30+
// expect(error.args[0][0]).to.equal(msg)
31+
// error.restore()
32+
// })
33+
})

0 commit comments

Comments
 (0)