【发布时间】:2018-11-09 15:17:12
【问题描述】:
我有一个 react + typescript 应用程序,我有一个使用 axios 完成的异步 api 调用。我想使用 Jest + Enzyme 测试该异步调用。
这就是我的行动
// load items callback
export function loadItemsSuccess(response) {
return {
type: LOAD_ITEMS,
items: response.data
};
}
// load items
export function loadItems() {
return function (dispatch) {
const authOptions = {
method: "GET",
url: "http://192.168.99.100:3000/items
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
json: true
};
return axios(authOptions).then(response => {
dispatch(loadItemsSuccess(response));
}).catch(error => {
console.log("Error loading items, error);
});
};
}
我的 reducer 简单地更新了 store:
case LOAD_ITEMS:
console.log(action.items);
return action.items;
【问题讨论】:
标签: javascript testing axios jestjs enzyme