¿如何使用 sinon spy 或 sinon 存根测试异步等待函数?

问题描述

我正在尝试测试几个使用 await 的函数,但覆盖范围并未涵盖使用 Sinon 的所有函数

这是我正在测试的功能

  public async GenerarSolicitud(
    selectedSearched: ISearchedBIT,selectedDocs: Array<IDocumentoBIT>,emailUser: string,) {
    try {
      const requestEntity = this.buildrequestEntity(
        selectedSearched,selectedDocs,);
      const request = await this.pnp.insertItem(
        ListNamePOARequest,requestEntity
      );

      const files = await this.descargararchivosSolicitudPOA(selectedDocs);

      const attachment = await this.pnp.addAttachmentToItem(
        ListNamePOARequest,request.ID,"ResumenPOA.zip",files
      );

      if (emailUser) {
        this.sendNewPOANotification(request.ID,[emailUser],attachment);
      }

      return request;
    } catch (err) {
      throw new Error(err);
    }
  }

这是测试:

test(`dado => un llamado GenerarSolicitud 
  cuando => idInit existe
  entonces => GenerarSolicitud esta definido`,async () => {

  buildrequestEntity.returnValues.push(Promise.resolve({ ID: 1 }))
  insertItem.returnValues.push(Promise.resolve({ ID: 1 }))
  descargararchivosSolicitudPOA.returnValues.push(Promise.resolve({ file: {} }))
  addAttachmentToItem.returnValues.push(Promise.resolve({}))
  sendNewPOANotification.resolves([])

  utilsPOA2.GenerarSolicitud({
    Grupo: "",Tematica: "",Especialidad: ""
  },[{
    Id: "2",ID: "",DescripcionDocumentoBIT: "des"
  }],user.email).then(res => {
    expect(res).tobedefined()
  }).catch()
})

这是覆盖范围:

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...