I need to write a test case for a function that returns a Promise with resolve and reject. Here's the function definition:
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;
}
I'm new to writing test cases for functions that handle promises. I've tried a few options but haven't been successful. Can anyone please assist me in handling test cases for both positive and negative scenarios?