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('播放状态切换', () => {
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
Although I don’t know if this is the right approach, after writing it this way, the watch code will be covered...