Skip to content

Commit 4d65406

Browse files
committed
chore: rebasing branch against dev
2 parents f9783fd + ec99da1 commit 4d65406

File tree

6 files changed

+50
-12
lines changed

6 files changed

+50
-12
lines changed

Diff for: packages/create-instance/create-instance.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import createScopedSlots from './create-scoped-slots'
1111
import { createStubsFromStubsObject } from './create-component-stubs'
1212
import { patchCreateElement } from './patch-create-element'
1313

14-
function createContext(options, scopedSlots) {
14+
function createContext(options, scopedSlots, currentProps) {
1515
const on = {
1616
...(options.context && options.context.on),
1717
...options.listeners
@@ -21,7 +21,7 @@ function createContext(options, scopedSlots) {
2121
...options.attrs,
2222
// pass as attrs so that inheritAttrs works correctly
2323
// propsData should take precedence over attrs
24-
...options.propsData
24+
...currentProps
2525
},
2626
...(options.context || {}),
2727
on,
@@ -98,10 +98,16 @@ export default function createInstance(
9898
parentComponentOptions._provided = options.provide
9999
parentComponentOptions.$_doNotStubChildren = true
100100
parentComponentOptions._isFunctionalContainer = componentOptions.functional
101+
const originalDataFn = parentComponentOptions.data
102+
parentComponentOptions.data = function() {
103+
const originalData = originalDataFn ? originalDataFn() : {}
104+
originalData.vueTestUtils_childProps = { ...options.propsData }
105+
return originalData
106+
}
101107
parentComponentOptions.render = function(h) {
102108
return h(
103109
Constructor,
104-
createContext(options, scopedSlots),
110+
createContext(options, scopedSlots, this.vueTestUtils_childProps),
105111
createChildren(this, h, options)
106112
)
107113
}

Diff for: packages/test-utils/src/create-local-vue.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @flow
22

33
import Vue from 'vue'
4+
import config from './config'
45
import cloneDeep from 'lodash/cloneDeep'
56

67
function createLocalVue(_Vue: Component = Vue): Component {
@@ -22,7 +23,10 @@ function createLocalVue(_Vue: Component = Vue): Component {
2223
}
2324
})
2425

25-
// config is not enumerable
26+
// Merge in the (possibly) modified config.
27+
// It needs to be done on the prototype for it to actually work throughout the runtime
28+
Object.assign(Vue.config, config)
29+
2630
instance.config = cloneDeep(Vue.config)
2731

2832
instance.config.errorHandler = Vue.config.errorHandler

Diff for: packages/test-utils/src/wrapper.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// @flow
22

3-
import Vue from 'vue'
43
import pretty from 'pretty'
54
import getSelector from './get-selector'
65
import { REF_SELECTOR, FUNCTIONAL_OPTIONS, VUE_VERSION } from 'shared/consts'
7-
import config from './config'
86
import WrapperArray from './wrapper-array'
97
import ErrorWrapper from './error-wrapper'
108
import { throwError, getCheckedEvent, isPhantomJS } from 'shared/util'
@@ -478,8 +476,6 @@ export default class Wrapper implements BaseWrapper {
478476
* Sets vm props
479477
*/
480478
setProps(data: Object): void {
481-
const originalConfig = Vue.config.silent
482-
Vue.config.silent = config.silent
483479
if (this.isFunctionalComponent) {
484480
throwError(
485481
`wrapper.setProps() cannot be called on a functional component`
@@ -531,10 +527,13 @@ export default class Wrapper implements BaseWrapper {
531527
// $FlowIgnore : Need to call this twice to fix watcher bug in 2.0.x
532528
this.vm[key] = data[key]
533529
}
530+
531+
if (this.vm && this.vm.$parent) {
532+
this.vm.$parent.vueTestUtils_childProps[key] = data[key]
533+
}
534534
})
535535
// $FlowIgnore : Problem with possibly null this.vm
536536
this.vm.$forceUpdate()
537-
Vue.config.silent = originalConfig
538537
}
539538

540539
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<script>
2+
export default {
3+
props: ['prop1'],
4+
data: function() {
5+
return {
6+
data1: null
7+
}
8+
},
9+
10+
watch: {
11+
prop1: {
12+
handler() {
13+
this.data1 = this.prop1
14+
},
15+
immediate: true
16+
}
17+
}
18+
}
19+
</script>
20+
<template>
21+
<h1>test</h1>
22+
</template>

Diff for: test/specs/config.spec.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ describeWithShallowAndMount('config', mountingMethod => {
6969
localVue
7070
})
7171
expect(wrapper.vm.prop1).to.equal('example')
72-
wrapper.setProps({
73-
prop1: 'new value'
74-
})
72+
wrapper.vm.prop1 = 'new value'
7573
expect(console.error).not.calledWith(sandbox.match('[Vue warn]'))
7674
})
7775

Diff for: test/specs/wrapper/setProps.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { compileToFunctions } from 'vue-template-compiler'
22
import ComponentWithProps from '~resources/components/component-with-props.vue'
33
import ComponentWithWatch from '~resources/components/component-with-watch.vue'
4+
import ComponentWithWatchImmediate from '~resources/components/component-with-watch-immediate.vue'
45
import { describeWithShallowAndMount, vueVersion } from '~resources/utils'
56
import { itDoNotRunIf } from 'conditional-specs'
67
import Vue from 'vue'
@@ -244,6 +245,14 @@ describeWithShallowAndMount('setProps', mountingMethod => {
244245
expect(wrapper.vm.propA).to.equal('value')
245246
})
246247

248+
it('correctly sets props in async mode when component has immediate watchers', async () => {
249+
const wrapper = mountingMethod(ComponentWithWatchImmediate)
250+
const prop1 = 'testest'
251+
wrapper.setProps({ prop1 })
252+
await Vue.nextTick()
253+
expect(wrapper.vm.prop1).to.equal(prop1)
254+
})
255+
247256
it('throws an error if node is not a Vue instance', () => {
248257
const message = 'wrapper.setProps() can only be called on a Vue instance'
249258
const compiled = compileToFunctions('<div><p></p></div>')

0 commit comments

Comments
 (0)