鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ vue單元測試 如何覆蓋promise對象里面的代碼

vue單元測試 如何覆蓋promise對象里面的代碼

.vue
login(){
  apiUser.login(this.phone, this.password).then((res) => {
    const data = res.data
    if (data.code === 200) {
      this.$store.commit('login')
      this.$store.commit('modifyUserId', data.profile.userId)
      this.storage(data.profile.userId, data.profile.nickname, data.profile.avatarUrl)
      alert('登錄成功!')
      this.close()
    } else {
      alert(res.data.msg)
    }
  })
}

.spec.js
it('輸入錯誤的手機(jī)號或密碼', () => {
  vm.phone = '123123123'
  vm.password = '12312'
  vm.login()
  expect()
})

例如這段代碼, 在test中調(diào)用login()后,箭頭函數(shù)里面的代碼沒有被覆蓋掉,請問在單測中如何寫呢??

回答
編輯回答
陌如玉

求教大佬啊。。。。。。。。。。。。。。。。

2017年7月22日 19:00