В настоящее время я сталкиваюсь с проблемой при использовании жасминового теста с обещаниями.
Ошибка «Необработанный отказ от обещания»: это означает, что мое обещание неправильно обрабатывает catch()
и then()
..
Вот мой тест:
it('tests the openRepo function with changed and invalid path', (done) => {
const OldPath = '/old';
const NewPath = '/invalid';
const ProjectModalBoolean = true;
component.path = OldPath;
component.openFolder = NewPath;
component.projectModalLoading = ProjectModalBoolean;
component.openRepo().then(() => {
expect(component.openFolder).toBe('');
expect(component.projectModalLoading).toBeFalsy();
done();
});
});
В функции openRepo
у меня есть следующий код:
return this.gitService.setPath(this.openFolder)
.then((data) => {
this.projectModalLoading = false;
this.projectModalVisible = false;
this.openFolder = '';
this.toastr.info(data.message, data.title);
})
.catch((data) => {
this.projectModalLoading = false;
this.openFolder = '';
this.toastr.error(data.message, data.title);
});
... который вызывает функцию:
async setPath(newPath) {
new Promise<ServiceResult>((resolve, reject) => {
if (newPath === '/new') {
resolve(new Object());
} else {
reject(new Object());
}
});
}
Кажется, проблема reject()
в setPath
, так как другой тест, проходящий через resolve()
, работает нормально
Любая помощь будет приветствоваться