【发布时间】:2019-04-15 07:27:42
【问题描述】:
我正在为返回 Promise 和 resolve 的函数编写测试用例,如下所示:
isAuthSuccess(): Promise<any> {
const promise = new Promise((resolve, reject) => {
if (this.userInfo) {
resolve();
} else {
const validUserUrl: string = this.cookieService.get('PPRC_VALID_USER');
if (validUserUrl) {
this.authenticateUser(validUserUrl)
.toPromise()
.then(
userInfo => {
if (userInfo) {
this.userInfo = userInfo;
this.loadResources(userInfo, resolve);
} else {
reject('500_1');
}
},
error => {
reject('500_1');
}
);
} else {
reject('500_1');
}
}
});
return promise;
}
我是为处理 promise 的函数编写测试用例的新手。检查了几个选项,但没有取得任何成功。请在上面帮助我处理正面和负面情况的测试用例。
【问题讨论】:
-
有人对此有解决方案
标签: typescript promise angular6 karma-jasmine