unit-testing - 在这个例子中如何模拟 api 调用?
问题描述
我不确定如何在unit-test
Vue中模拟这个 API 调用
让我失望的是构成 API url 的变量。
export default {
name: "Jobs",
data() {
return {
job_execs: []
}
},
created() {
this.JobExecEndpoint = process.env.VUE_APP_UATU_URL + '/api/v1/job_execution/?tool='+this.$route.params.tool+'&job='+this.$route.params.job+'&id='+this.$route.params.id
fetch(this.JobExecEndpoint)
.then(response => response.json())
.then(body => {
this.job_execs.push({
'code_checkouts': body[0].code_checkouts,
})
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
解决方案
推荐阅读
- r - 重现插入符号混淆矩阵敏感性和特异性(它们似乎被交换)和 PPV(似乎被标记为 NPV)
- jquery - 如何使用 json 文件对我的数据表进行服务器端处理?
- linked-list - LinkedList 堆栈结构 Big O
- json - 如何使用 jq 加入 json 文件?
- r - 如何解决网页抓取功能中的“引用字符串中的 EOF”?
- python - 从嵌套 Json 响应中提取键和值数据的简单方法
- c# - Bot Framework Emulator v4.0:模拟组和多个用户
- asp.net-core-mvc - 是否可以添加自定义接受页面以登录亚马逊
- node.js - npm 错误!缺少脚本:部署
- unity3d - Unity - 尝试在 Mapbox 中的特定位置添加项目