[Vuejs]-Vue.js + Avoriaz : how to test a watcher?

0๐Ÿ‘

U mistaked the prop,use :checked instead

0๐Ÿ‘

I should write my expect(actions.updateList() . within a $nextTick block

  describe('switch checkbox', () => {
    it('calls store action updateList when item checkbox is switched', (done) => {
      const id = '3'
      const item = { text: 'Bananas', checked: true }
      const wrapper = mount(ItemComponent, { propsData: { item, id }, store })
      // switch item.checked to false
      wrapper.setProps({ item: { text: 'Bananas', checked: false } })
      expect(wrapper.vm.$props.item.checked).to.equal(false)
      wrapper.find('input')[0].trigger('input')
      wrapper.vm.$nextTick(() => {
        expect(actions.updateList.calledOnce).to.equal(true)
        done()
      })
    })
  })

then my test is OK

 ItemComponent.vue
    switch checkbox
      โœ“ calls store action updateList when item checkbox is switched

Leave a comment