Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing Loopback4服务单元测试:我是loopbakck4的新手,需要帮助为Wait Promise编写单元测试;_Unit Testing_Loopback4 - Fatal编程技术网

Unit testing Loopback4服务单元测试:我是loopbakck4的新手,需要帮助为Wait Promise编写单元测试;

Unit testing Loopback4服务单元测试:我是loopbakck4的新手,需要帮助为Wait Promise编写单元测试;,unit-testing,loopback4,Unit Testing,Loopback4,我的文件xyz-operations.service.ts中有一个函数,其代码块如下: async addRoleLevel(data: RoleLevel[], userTenantId: string) { const promises: Promise<UserLevelResource>[] = []; data.forEach(rl => { promises.push( this.userLevelResourceRepo

我的文件xyz-operations.service.ts中有一个函数,其代码块如下:

async addRoleLevel(data: RoleLevel[], userTenantId: string) {
    const promises: Promise<UserLevelResource>[] = [];
    data.forEach(rl => {
      promises.push(
        this.userLevelResourceRepo.create({
          resourceValue: rl.resourceId,
          resourceName: this.getTotalPermissions(rl.permissions),
          userTenantId,
        }),
      );
    });
    await Promise.all(promises);
}
我是否走对了路需要指导。尽管在运行命令时npm运行测试我仍面临以下错误 AssertionError:预期[Promise]等于数组[undefined]

需要关于如何进行的指导

it('returns undefined after adding role level.', async () => {
        const roleLevelArray = [{"resourceId": "Test Resource","isOrg": true,permissions: PermissionMap.VIEW}];
        const result = roleLevelOperationsService.addRoleLevel(roleLevelArray, tenantId);
        expect(result).which.eql([undefined]);
    });