Skip to content

Commit

Permalink
fix vuejs#455 and remove code for vuejs#582
Browse files Browse the repository at this point in the history
  • Loading branch information
38elements committed Jun 1, 2018
1 parent 4952874 commit a7d0a14
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
14 changes: 0 additions & 14 deletions packages/create-instance/create-instance.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @flow

import Vue from 'vue'
import cloneDeep from 'lodash/cloneDeep'
import { addSlots } from './add-slots'
import { addScopedSlots } from './add-scoped-slots'
import addMocks from './add-mocks'
Expand Down Expand Up @@ -93,19 +92,6 @@ export default function createInstance (
addAttrs(vm, options.attrs)
addListeners(vm, options.listeners)

vm.$_vueTestUtils_mountingOptionsSlots = options.slots
vm.$_vueTestUtils_originalSlots = cloneDeep(vm.$slots)
vm.$_vueTestUtils_originalUpdate = vm._update
vm._update = function (vnode, hydrating) {
// updating slot
if (this.$_vueTestUtils_mountingOptionsSlots) {
this.$slots = cloneDeep(this.$_vueTestUtils_originalSlots)
addSlots(this, this.$_vueTestUtils_mountingOptionsSlots)
vnode = this._render()
}
this.$_vueTestUtils_originalUpdate(vnode, hydrating)
}

if (options.scopedSlots) {
if (window.navigator.userAgent.match(/PhantomJS/i)) {
throwError('the scopedSlots option does not support PhantomJS. Please use Puppeteer, or pass a component.')
Expand Down
14 changes: 14 additions & 0 deletions packages/test-utils/src/set-watchers-to-sync.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { VUE_VERSION } from './consts'

function setDepsSync (dep) {
dep.subs.forEach(setWatcherSync)
}
Expand All @@ -24,4 +26,16 @@ export function setWatchersToSync (vm) {
setWatcherSync(vm._watcher)

vm.$children.forEach(setWatchersToSync)
// preventing double registration
if (!vm.$_vueTestUtils_updateInSetWatcherSync) {
vm.$_vueTestUtils_updateInSetWatcherSync = vm._update
vm._update = function (vnode, hydrating) {
this.$_vueTestUtils_updateInSetWatcherSync(vnode, hydrating)
if (VUE_VERSION >= 2.1 && this._isMounted && this.$options.updated) {
this.$options.updated.forEach((handler) => {
handler.call(this)
})
}
}
}
}
1 change: 0 additions & 1 deletion test/specs/mounting-options/slots.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
const wrapper5 = mountingMethod(ComponentWithSlots, { slots: { default: '1{{ foo }}2' }})
expect(wrapper5.find('main').html()).to.equal('<main>1bar2</main>')
wrapper5.trigger('keydown')
expect(wrapper5.find('main').html()).to.equal('<main>1BAR2</main>')
const wrapper6 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p><p>2</p>' }})
expect(wrapper6.find('main').html()).to.equal('<main><p>1</p><p>2</p></main>')
const wrapper7 = mountingMethod(ComponentWithSlots, { slots: { default: '1<p>2</p>3' }})
Expand Down
35 changes: 35 additions & 0 deletions test/specs/mounting-options/sync.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sinon from 'sinon'
import { describeWithShallowAndMount } from '~resources/utils'

describeWithShallowAndMount('options.sync', (mountingMethod) => {
Expand Down Expand Up @@ -110,4 +111,38 @@ describeWithShallowAndMount('options.sync', (mountingMethod) => {
done()
})
})

it('call updated when sync is not false', () => {
const childComponentSpy = sinon.stub()
const ChildComponent = {
template: '<div>{{ foo }}</div>',
props: ['foo'],
updated () {
childComponentSpy()
}
}
const spy = sinon.stub()
const TestComponent = {
template: '<div>{{ foo }}<child-component :foo="foo" /></div>',
data () {
return {
foo: 'foo'
}
},
updated () {
spy()
}
}
const wrapper = mountingMethod(TestComponent, {
stubs: { 'child-component': ChildComponent },
sync: true
})
expect(spy.notCalled).to.equal(true)
expect(childComponentSpy.notCalled).to.equal(true)
expect(wrapper.html()).to.equal('<div>foo<div>foo</div></div>')
wrapper.vm.foo = 'bar'
expect(spy.calledOnce).to.equal(true)
expect(childComponentSpy.calledOnce).to.equal(true)
expect(wrapper.html()).to.equal('<div>bar<div>bar</div></div>')
})
})

0 comments on commit a7d0a14

Please sign in to comment.