0
在我Vue.js项目中,我有以下Vuex行动:测试Vuex行动调用外部API
import { HTTP } from '@/services/http'
export const actions = {
loginUser ({ commit }, params) {
HTTP.post(
'v1/login',
{ email: params.email, password: params.password }
).then(response => {
localStorage.setItem('access_token', response.data.token)
commit('SET_USER', response.data)
}).catch(error => {
commit('SET_LOGIN_ERROR', error.response.data.error)
})
}
}
我使用摩卡+噶单元测试。我该如何测试该操作?
在我们进入这究竟是为什么甚至懒得这样做呢?如果您依赖于外部API调用,那么您可能会怀疑测试的真实可靠性和独立性。从那个电话中嘲笑你需要的东西不是更好吗? –