typescript 玩笑-在方法中掩盖承诺

ykejflvf  于 2022-11-18  发布在  TypeScript
关注(0)|答案(1)|浏览(118)

我有一个方法,在执行几行代码后调用promise-

const handleDownload = () =>{
  
  if(!currentItem){
     return;
  }
  setDownloadState(true);
  setDeleteState(false);
  Task.DeleteAttachment(currentItem.FileId)
      .then((res)=>{
             if(res.status===200){
                   ...
                   ...
                   ...
             }
             else{
                dispatch(MarkError(true));
             }
          })
         .catch((error)=>{ 
                dispatch(ReportError(error));
               });
           }

.then((res)=>{之前的所有行都包含在测试覆盖报告中。但是promise then和catch没有包含在内。
我怎样才能覆盖它们?

b91juud3

b91juud31#

在您的测试用例中,您可以使用async await:

it('test', async() => {
  await request(app).post('/yourAPI').expect(200) // this route will call handleDownload
})

相关问题