【发布时间】:2021-06-23 07:41:57
【问题描述】:
所以,我想测试(使用 Jest)一个函数,该函数返回一个包含 axios 请求(作为另一个嵌套承诺)的承诺,并在 then 和 catch 块中解析外部承诺。
功能类似这样:
fetchFunction() {
return new Promise((resolve, reject) => {
if (!this.valid) {
this.value = 1;
return resolve();
}
this.someModel.$get()
.then(() => {
this.value = 2;
return resolve();
})
.catch(e => {
this.value = 3;
return reject(e);
});
});
},
【问题讨论】:
标签: javascript promise axios jestjs es6-promise