Skip to content

Commit a313af2

Browse files
committed
chore: Add async test with immediate watcher
1 parent 9dc90a3 commit a313af2

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed
Lines changed: 22 additions & 0 deletions
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>

test/specs/config.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ describeWithShallowAndMount('config', mountingMethod => {
104104
localVue
105105
})
106106
expect(wrapper.vm.prop1).to.equal('example')
107-
wrapper.setProps({
108-
prop1: 'new value'
109-
})
107+
wrapper.vm.prop1 = 'new value'
110108
expect(console.error).calledWith(sandbox.match('[Vue warn]'))
111109
})
112110
})

test/specs/wrapper/setProps.spec.js

Lines changed: 12 additions & 0 deletions
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,17 @@ 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+
sync: false
251+
})
252+
253+
const prop1 = 'testest'
254+
wrapper.setProps({ prop1 })
255+
await Vue.nextTick()
256+
expect(wrapper.vm.prop1).to.equal(prop1)
257+
})
258+
247259
it('throws an error if node is not a Vue instance', () => {
248260
const message = 'wrapper.setProps() can only be called on a Vue instance'
249261
const compiled = compileToFunctions('<div><p></p></div>')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy