Unexpected behaviour when watching
See original GitHub issueVersion
1.0.0-beta.13
Reproduction link
https://github.com/tbuteler/vue-test-utils-issue
Steps to reproduce
Clone the repository, then run:
yarn install
yarn run tests
What is expected?
Component:
<template>
<div id="app">
<div>
<pre>data.text: <em>{{ text }}</em></pre>
</div>
<!-- Tests fail in 1.0.0-beta.13 with .fails portion of the code -->
<div class="fails">
<pre>computed.text: <em>{{ computedText }}</em></pre>
</div>
</div>
</template>
<script>
export default {
name: 'app',
data () {
return {
text: '',
basket: []
}
},
computed: {
computedText () {
return this.text
}
},
watch: {
text () {
this.basket.push(this.computedText)
}
}
}
</script>
Test:
import { shallow } from '@vue/test-utils'
import App from '../src/App.vue'
describe('App.vue', () => {
it('updates computed properties', () => {
const wrapper = shallow(App)
expect(wrapper.vm.text).toBe('')
expect(wrapper.vm.basket).toEqual([])
wrapper.setData({ text: 'foo' })
expect(wrapper.vm.text).toBe('foo')
expect(wrapper.vm.computedText).toBe('foo')
expect(wrapper.vm.basket).toEqual(['foo']) // Fails
})
})
In the text
watch handler, I expected the computed property to have been updated to the latest value of text
.
What is actually happening?
The computed property is somehow lagging behind. Curiously, this only happens when the computed property is actually being rendered inside the template, otherwise it behaves as expected.
This issue was not present in 1.0.0-beta.12, regardless of what the template contains. From the release information, I would suspect it has something to do with the new sync
functionality.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Expected and Unexpected Behaviour: Introduction - YouTube
This video explains the meaning of expected and unexpected behaviors. This is an important foundational social skills to teach young ...
Read more >Zones of Regulation - Expected and Unexpected Behaviors ...
Zones of Regulation - Expected and Unexpected Behaviors with Mrs. Connell & Mrs. Conner. 16K views 1 year ago.
Read more >Hidden Rules and Expected and Unexpected Behavior
Hidden Rules and Expected and Unexpected Behavior. null watching now · null total views. Playback speed. Popout. Overflow menu. Keyframe Interval:.
Read more >Teaching Expected and Unexpected Behaviors
Expected behavior is simply behavior that is normal, reasonable and anticipated. Unexpected behavior is behavior that is out of the norm, and is ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Tested this today with my actual suite and its components, which are far more complex than the examples above and everything worked as expected. Thanks for your effort!
This is a bug caused by dependencies running in the incorrect order. I’ve created a fix that will be released in the next version.
For the moment, you will need to set
sync
to false and useVue.nextTick
:Alternatively, you can use beta.12.