【发布时间】:2020-06-24 12:13:03
【问题描述】:
我想开玩笑地测试 axios 请求。 问题是我已经搜索了很多方法,但没有理解其中的一堆,我被困住了。 例如这里是我获取请求
componentDidMount() {
const { getAll, setPageCount } = this.props.actions;
axios
.get(`http://localhost:8080/${localStorage.getItem("username")}`, {
headers: {
"auth-token": localStorage.getItem("auth-token"),
},
})
.then((res) => {
getAll(res.data);
setPageCount();
})
.catch((err) => {
console.log("-----token", localStorage.getItem("auth-token"));
console.log("err", err);
});
}
我怎样才能开玩笑呢? 提前致谢
【问题讨论】:
-
对于 Jest 测试,您是否希望 API 实际调用;向端点发送请求还是简单地模拟 axios API?
-
模拟 axios API。
-
你看过Mock Modules吗?
标签: javascript reactjs jestjs axios