Vue-test-utils: Watch does not work

Created on 13 Jan 2019  Â·  4Comments  Â·  Source: vuejs/vue-test-utils

Version

1.0.0-beta.24

Reproduction link

https://jsfiddle.net/r8Lq6h2b/

Steps to reproduce

template:

 <b-form-select :options="selectList" v-model="selected.property" id="bselect"></b-form-select>

data:

  data () {
    return {
      selectList: [],
      selected: {}
    }
  }

created:

      this.selectList=['item1','item2','item3'],
      this.selected={property:'item1',name:'name'}

watch:

watch: {
 'selected.property': function (value) {
          console.log('selected.property changed')
      this.selected.name='watchChanged'
 }
}

spec.js:

        before(async () => {
          const options = wrapper.find('#bselect')
          console.log('wrapper.vm.selected.property1:'   wrapper.vm.selected.property)
          options.at(1).setSelected()
          await wrapper.vm.$nextTick()
        })
        it('selected.property changed', () => {
           console.log('wrapper.vm.selected.property2:'   wrapper.vm.selected.property)
           expect(wrapper.wm.selected.name).to.equal('watchChanged')
        })

What is expected?

expect(wrapper.wm.selected.name).to.equal('watchChanged')

expect is true

What is actually happening?

expect(wrapper.wm.selected.name).to.equal('watchChanged')
is run failed,return false
console:

wrapper.vm.selected.property1:item1
wrapper.vm.selected.property:2item2

but

console.log('selected.property changed') 

It is not printed on the console。


I feel very strange, can you help me?

need repro

All 4 comments

Please can you provide a runnable reproduction as a GitHub repository

The problem is solved

@azui007 How did you solve this problem?

hey @azui007 it would be great if you share your knowledge about how you have solved the problem as it would help others

Was this page helpful?
0 / 5 - 0 ratings