亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - Using vue official scaffolding for unit testing, how to cover variables in watch?
typecho
typecho 2017-06-27 09:19:20
0
1
1280

The watch in the component is as follows:

player(isPlay) {
  if (isPlay) {
    this.playState = 'play'
  } else {
    this.playState = 'pause'
  }
}

The relevant use cases in the test file Home.spec.js are as follows

it('播放狀態(tài)切換', () => {
  const Constructor = Vue.extend(Home)
  const vm = new Constructor().$mount()
  vm.playerShow = true
  Vue.nextTick( () => {
    expect(vm.playState).to.equal("play")
  })
  vm.playerShow = false
  Vue.nextTick( () => {
    expect(vm.playState).to.equal("pause")
    done()
  })
})

After writing this, check the coverage report and find that the watch part of the code in the component is not covered (all are red)
Please tell me how to write a use case to cover the watch code

typecho
typecho

Following the voice in heart.

reply all(1)
大家講道理

Although I don’t know if this is the right approach, after writing it this way, the watch code will be covered...

it('播放狀態(tài)切換', () => {
  const Constructor = Vue.extend(Home)
  const vm = new Constructor().$mount()
  vm._watchers[0].cb(true)
  Vue.nextTick( () => {
    expect(vm.playState).to.equal("play")
  })
  vm._watchers[0].cb(false)
  Vue.nextTick( () => {
    expect(vm.playState).to.equal("pause")
    done()
  })
})
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template