Skip to content
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

remove transition data from transitionStub #423

Merged
merged 1 commit into from
Feb 11, 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
18 changes: 1 addition & 17 deletions src/components/TransitionStub.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,6 @@ export const camelize = (str: string): string => {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
}

function extractTransitionData (comp: Component): Object {
const data = {}
const options = comp.$options
// props
for (const key in options.propsData) {
data[key] = comp[key]
}
// events.
// extract listeners and pass them directly to the transition methods
const listeners: ?Object = options._parentListeners
for (const key in listeners) {
data[camelize(key)] = listeners[key]
}
return data
}

function hasParentTransition (vnode: VNode): ?boolean {
while ((vnode = vnode.parent)) {
if (vnode.data.transition) {
Expand Down Expand Up @@ -125,7 +109,7 @@ export default {
? (String(child.key).indexOf(id) === 0 ? child.key : id + child.key)
: child.key

const data: Object = (child.data || (child.data = {})).transition = extractTransitionData(this)
const data: Object = (child.data || (child.data = {}))
const oldRawChild: ?VNode = this._vnode
const oldChild: ?VNode = getRealChild(oldRawChild)
if (child.data.directives && child.data.directives.some(d => d.name === 'show')) {
Expand Down
36 changes: 31 additions & 5 deletions test/specs/components/TransitionStub.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ComponentWithTransition from '~resources/components/component-with-transition.vue'
import TransitionStub from '~src/components/TransitionStub'
import { mount } from '~vue-test-utils'
import { describeWithShallowAndMount } from '~resources/test-utils'

describe('TransitionStub', () => {
describeWithShallowAndMount('TransitionStub', (mountingMethod) => {
it('update synchronously when used as stubs for Transition', () => {
const wrapper = mount(ComponentWithTransition, {
const wrapper = mountingMethod(ComponentWithTransition, {
stubs: {
'transition': TransitionStub
}
Expand All @@ -14,6 +14,32 @@ describe('TransitionStub', () => {
expect(wrapper.text()).contains('b')
})

it('does not add v-leave class to children', () => {
const TestComponent = {
template: `
<div>
<transition name="expand">
<nav v-show="isShown" />
</transition>
<button @click="isShown = !isShown" />
</div>
`,
data: () => ({
isShown: false
})
}
const wrapper = mountingMethod(TestComponent, {
stubs: {
'transition': TransitionStub
}
})
expect(wrapper.find('nav').visible()).to.equal(false)
wrapper.find('button').trigger('click')
expect(wrapper.find('nav').visible()).to.equal(true)
wrapper.find('button').trigger('click')
expect(wrapper.find('nav').visible()).to.equal(false)
})

it('logs error when has multiple children', () => {
const TestComponent = {
template: `
Expand All @@ -22,7 +48,7 @@ describe('TransitionStub', () => {
}
const msg = '[vue-test-utils]: <transition> can only be used on a single element. Use <transition-group> for lists.'
const error = sinon.stub(console, 'error')
mount(TestComponent, {
mountingMethod(TestComponent, {
stubs: {
'transition': TransitionStub
}
Expand All @@ -47,7 +73,7 @@ describe('TransitionStub', () => {
}
}
}
const wrapper = mount(TestComponent, {
const wrapper = mountingMethod(TestComponent, {
stubs: {
'transition': TransitionStub
}
Expand Down