what i want to know is that how can i test the watch with vue-test-utils and jest.
i had tried to do like this.
the code above is to featch data from the server,it will return a object of promise
this.$api.querySexListByGoodsCode(data)
appointment.js
watch: {
addGoodsCodeList () {
const data = {
goodsCode: this.orderInfo.goodsCode,
addGoodsCodes: this.addGoodsCodeListStr
}
console.log('========')
console.log(this.$api.querySexListByGoodsCode)
console.log('========')
this.$api.querySexListByGoodsCode(data).then(res => {
if (res.data.SZ_HEAD.RESP_CODE === 'S0000') {
this.sexs = res.data.SZ_BODY.sexList
} else if (['B0201', 'B0205', 'SE3006', 'SE1004'].includes(res.data.SZ_HEAD.RESP_CODE)) {
this.$router.push({ name: 'login' })
} else {
this.$dialog.toast(res.data.SZ_HEAD.RESP_MSG)
}
})
},
appointment.spec.js
it('this is what i did ', () => {
let addGoodsCodeList
wrapper.setData({
orderInfo: {
goodsCode: 'gds1213223'
},
addGoodsCodeListStr: 'gds1312331231'
})
addGoodsCodeList = jest.spyOn(api, 'querySexListByGoodsCode')
wrapper.vm.$nextTick(() => {
expect(addGoodsCodeList).toBeCalled()
next()
})
addGoodsCodeList.mockClear()
})
but ,i got the wrong message in my terminal
this is the wrong message :
[Vue warn]: Computed property "addGoodsCodeListStr" was assigned to but it has no setter.
found in
--->
console.error node_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]: Error in nextTick: "Error: expect(jest.fn()).toBeCalled()
Expected mock function to have been called, but it was not called.
i hope to get the help to solve to this problem