Unit testing Loopback4服务单元测试:我是loopbakck4的新手,需要帮助为Wait Promise编写单元测试;
我的文件xyz-operations.service.ts中有一个函数,其代码块如下: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
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]);
});