小编Shr*_*rma的帖子

React Jest:-node:internal/process/promises:246triggerUncaughtException(err, true /* fromPromise */);

我在反应中有以下代码。

useEffect(() => {
        (async () => {
            await httpClient
                .get(`${config.resourceServerUrl}/inventory/`)
                .then((response) => {
                    setSponsor(response.data.sponsor);
                    setAddress(response.data.address);
                    setPhaseOfTrial(response.data.phaseOfTrial);
                })
                .catch((error) => {
                    alert(error);
                });
        })();
    }, []);
Run Code Online (Sandbox Code Playgroud)

这段代码运行成功。唯一的问题是,它在玩笑测试用例中失败了。

describe('ListInventory', () => {
    it('should render successfully', () => {
        const { baseElement } = render(<ListInventory />);
        expect(baseElement).toBeTruthy();
    });
});
Run Code Online (Sandbox Code Playgroud)

下面是错误。

node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled …
Run Code Online (Sandbox Code Playgroud)

javascript callback promise reactjs jestjs

11
推荐指数
2
解决办法
7万
查看次数

在react中使用axios上传文件

我正在react使用上传文件axios。当我在做的时候

alert(values.attachedFile[0]);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

但是当我发送values.attachedFile[0]帖子axios请求时,事情就发生了。

  const { result } = await axios.post(app.resourceServerUrl + '/file/upload', {
        data: values.attachedFile[0],
        headers: {
            'Content-Type': 'multipart/form-data',
        },
    });
Run Code Online (Sandbox Code Playgroud)

但作为请求的一部分是空的。

在此输入图像描述

我犯了什么错误?

javascript api reactjs axios nestjs

8
推荐指数
1
解决办法
2万
查看次数

TypeORM/NestJS 中的分页

我必须在findAll()方法中引入分页。我真的不知道该怎么做。我尝试过,但它给出了很多错误。我使用了findAndCount()给出的方法typeorm,但我不确定它是如何工作的。

截至目前,以下方法返回所有记录。我需要一次返回10条记录。请建议我需要做什么修改。

async findAll(queryCertificateDto: QueryCertificateDto,page=1):  Promise<PaginatedResult> {
    
    let { country, sponser } = queryCertificateDto;

    const query = this.certificateRepository.createQueryBuilder('certificate');

    if (sponser) {
        sponser = sponser.toUpperCase();
        query.andWhere('Upper(certificate.sponser)=:sponser', { sponser });
    }

    if (country) {
        country = country.toUpperCase();
        query.andWhere('Upper(certificate.country)=:country', { country });
    }      
    const  certificates = query.getMany();     
    return certificates;
}
Run Code Online (Sandbox Code Playgroud)

这是PaginatedResult文件。

 export class PaginatedResult {
        data: any[];
        meta: {
          total: number;
          page: number;
          last_page: number;
        };
      }
  
Run Code Online (Sandbox Code Playgroud)

我尝试更改findAll()butwhere子句的代码给出错误。我不知道如何query.getMany()处理pagination …

javascript orm backend typeorm nestjs

4
推荐指数
1
解决办法
7592
查看次数

Oracle云中IAM、IDCS和OCI的区别

我对这三个术语感到困惑。我所知道的OCI是Oracle提供的基础设施,IAM是用户,IDCS是身份云服务。但我不明白差异和术语。

Is IAM user and normal user are same?

is OCI and IDCS are same?

What exactly IDCS is?
Run Code Online (Sandbox Code Playgroud)

cloud oracle plsqldeveloper oracle-sqldeveloper oracle-cloud-infrastructure

2
推荐指数
2
解决办法
7173
查看次数

React 中的可搜索下拉菜单

我有以下反应列表。

<select
    id="sponsor" 
    name="sponsor"
    className="form-control"
    placeholder="Sponsor"
    }
    >
    <option value="" selected>Please select the sponsor</option>
     {
     active && result.map((sponsor:Sponsor,index:number)=>
          <option  value={sponsor.id} >{sponsor.name}</option>    
      )
    }

</select>
Run Code Online (Sandbox Code Playgroud)

它工作得很好。现在我需要将其更改为可搜索列表。我在下面做了。

     import VirtualizedSelect from 'react-virtualized-select'
    import "react-virtualized-select/styles.css";
    import 'react-virtualized/styles.css'
     

 <VirtualizedSelect
        id="sponsor" 
        name="sponsor"
        className="form-control"
        placeholder="Sponsor"
        options={ active && result.map((sponsor:Sponsor,index:number)=>
            {sponsor.name}
          
        )}

     >
       </VirtualizedSelect> 
Run Code Online (Sandbox Code Playgroud)

现在列表中没有任何内容。基本上我的要求是使列表可搜索并将API 数据插入该列表。

你能帮我做同样的事吗?任何其他选择也会非常有帮助

Edit1:-
Run Code Online (Sandbox Code Playgroud)

我需要如下列表。第一行“请选择赞助商”

在此输入图像描述

javascript reactjs react-select react-virtualized react-hooks

2
推荐指数
1
解决办法
1万
查看次数

Nestjs 中角色保护文件的测试用例

我不确定如何编写guardin的单元测试用例文件nestjs。我有以下Role.guard.ts文件。我必须创建Role.guard.spec.ts文件。有人可以帮忙吗?

import { Injectable, CanActivate, ExecutionContext, Logger } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { ROLES_KEY } from './roles.decorator';
import { Role } from './role.enum';

@Injectable()
export class RolesGuard implements CanActivate {
    constructor(private reflector: Reflector) {}

    canActivate(context: ExecutionContext): boolean {
        const requiredRoles = this.reflector.getAllAndOverride<string[]>(ROLES_KEY, [
            context.getHandler(),
            context.getClass(),
        ]);

        const { user } = context.switchToHttp().getRequest();

        if (!user.role) {
            Logger.error('User does not have a role set');
            return false;
        }

        if (user.role …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing jestjs typeorm nestjs

1
推荐指数
1
解决办法
1405
查看次数