小编A M*_*eto的帖子

Jest 检测到以下 1 个打开句柄可能会阻止 Jest 退出: TCPSERVERWRAP

我正在这里进行基本的端到端测试,目前它失败了,但首先我无法摆脱打开的手柄。

\n
Ran all test suites.\n\nJest has detected the following 1 open handle potentially keeping Jest from exiting:\n\n  \xe2\x97\x8f  TCPSERVERWRAP\n\n      40 |     }\n      41 |     return request(app.getHttpServer())\n    > 42 |       .post('/graphql')\n         |        ^\n      43 |       .send(mutation)\n      44 |       .expect(HttpStatus.OK)\n      45 |       .expect((response) => {\n\n      at Test.Object.<anonymous>.Test.serverAddress (../node_modules/supertest/lib/test.js:61:33)\n      at new Test (../node_modules/supertest/lib/test.js:38:12)\n      at Object.obj.<computed> [as post] (../node_modules/supertest/index.js:27:14)\n      at Object.<anonymous> (app.e2e-spec.ts:42:8)\n
Run Code Online (Sandbox Code Playgroud)\n
import { Test, TestingModule } from '@nestjs/testing'\nimport { HttpStatus, INestApplication } from "@nestjs/common";\nimport * as request from 'supertest'\nimport { AppModule …
Run Code Online (Sandbox Code Playgroud)

typescript supertest jestjs graphql nestjs

36
推荐指数
4
解决办法
6万
查看次数

NestJS EntityMetadataNotFoundError:找不到“存储库”的元数据

我知道有很多关于这个主题的帖子。我真的很难理解我到底想做什么来解决这个问题。使用 Postman,当我尝试命中路线时,出现以下错误:

ERROR [ExceptionsHandler] No metadata for "OrganizationsRepository" was found.
EntityMetadataNotFoundError: No metadata for "OrganizationsRepository" was found.
Run Code Online (Sandbox Code Playgroud)

这是我的代码的样子

// app.module.ts

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'postgres',
      host: 'localhost',
      port: 5432,
      database: 'my-database',
      username: 'postgres',
      password: 'password',
      autoLoadEntities: true,
      synchronize: true,
    }),
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    OrganizationsModule,
  ],
  controllers: [],
  providers: [],
  exports: [],
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)
// organizations.repository.ts

@EntityRepository(Organization). // this is showing as deprecated
export class OrganizationsRepository extends Repository<Organization> {
...
}
Run Code Online (Sandbox Code Playgroud)
// organization.entity.ts

@Entity({ name: 'organizations' …
Run Code Online (Sandbox Code Playgroud)

typescript typeorm nestjs

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

如何在 TypeOrm 实体中添加枚举数组?

我正在进行大量研究和实验,以在我的实体中使用枚举数组。

import { Program } from '../../program/entities/program.entity'
import {
  Column,
  Entity,
  JoinTable,
  ManyToMany,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm'
import { Exercise } from '../../exercise/entities/exercise.entity'
import { WeekDays } from '../types/week-days.enum'

@Entity()
export class Workout {
  // [...]

  @Column({
    type: 'enum',
    enum: WeekDays,
    default: [],
    array: true,
  })
  scheduledDays?: WeekDays[]

  constructor(partial: Partial<Workout> | {} = {}) {
    Object.assign(this, partial)
  }
}

Run Code Online (Sandbox Code Playgroud)

不幸的是它给了我这个错误。

QueryFailedError: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version …
Run Code Online (Sandbox Code Playgroud)

arrays enums entity typescript typeorm

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

类型错误:无法读取未定义 faker-js faker 的属性“uuid”

我正在尝试使用faker-js包,但我意外地得到了一个尝试使用的TypeError: Cannot read property 'uuid' of undefined变量businessIdfaker.datatype.uuid()

当我忘记安装时通常会发生这种情况faker-js,但这里不是这种情况,我检查是否导入了这个包。因此我对我在这里做错了什么一无所知。

// eslint-disable-next-line import/order
const { initConfig } = require('../../../config');

initConfig();

const sinon = require('sinon');
const faker = require('@faker-js/faker');
const { retryAsyncCall } = require('../../../src/common/helpers/retry-async');
const { createFacebookAdVideoFromUrl } = require('../../../src/common/controllers/facebook/api');

function createPayloadDataBuilder(payload = {}) {
  const template = {
    accountId: faker.datatype.uuid(),
    publicLink: faker.internet.url(),
    videoName: faker.lorem.word(),
    facebookToken: undefined,
    params: null,
    businessId: faker.datatype.uuid(),
  };
  return { ...payload, ...template };
}

describe('Facebook Gateway', () => {
  describe('createFacebookAdVideoFromUrl', …
Run Code Online (Sandbox Code Playgroud)

javascript testing node.js requirejs faker.js

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

如何从WebStorm代码分析中排除node_modules(左下角名为“问题”)

我在我的工作流程中广泛依赖此功能,但由于某些原因,此功能现在警告我来自 的所有问题node_modules,这显然我对此不感兴趣。

在此输入图像描述

如何在没有nodes_modules文件夹的情况下让 WebStorm 分析我的整个项目问题?

code-analysis compilation webstorm typescript tsconfig

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

“ID”类型的变量“$userId”用于期望类型“ID!”的位置

我正在尝试使用 npm 包发出 graphql 请求graphql-request。我正在发现模板文字的使用。

   async getCandidate(userId: number) {
            const query = gql`
            query($userId: ID){
              candidate(id: $userId){
                id _id source phone
              }
            }
            `
            const variables = {userId: "/api/candidates/" + userId}
            return await request(GRAPHQL_URL, query, variables)
        }
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用该usedId变量,但出现错误:

Variable "$userId" of type "ID" used in position expecting type "ID!".: {"response":{"errors":[{"message":"Variable \"$userId\" of type \"ID\" used in position expecting type \"ID!\".","extensions":{"category":"graphql"},"locations":[{"line":2,"column":9},{"line":3,"column":19}]}],"status":200},"request":{"query":"\n\t\tquery($userId: ID){\n\t\t  candidate(id: $userId){\n\t\t    id _id source phone\n\t\t  }\n\t\t}\n\t\t","variables":{"userId":"/api/candidates/1"}
Run Code Online (Sandbox Code Playgroud)

typescript template-strings graphql

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

Jest Matcher 错误:接收到的值必须是一个承诺或一个返回承诺的函数

我是 TDD 从业者,我正在尝试实现一个异常。

下面是测试代码:

  it.each([[{ id: '', token: '', skills: [''] }, 'Unknown resource']])(
    'should return an Exception when incorrect dto data',
    async (addSkillsDto: AddSkillsDto) => {
      await expect(() => {
        controller.addSkills(addSkillsDto)
      }).rejects.toThrow()
    }
  )
Run Code Online (Sandbox Code Playgroud)

下面是相关代码:

  @Post('candidate/add-skills')
  async addSkills(
    @Body() skills: AddSkillsDto,
  ): Promise<StandardResponseObject<[]>> {
    const data = await this.candidateService.addSkills(skills)
    console.log(data, !data)
    if (!data) throw new HttpException('Unknown resource', HttpStatus.NOT_FOUND)
    else
      return {
        success: true,
        data,
        meta: null,
        message: ResponseMessage.SKILLS_ADDED,
      }
  }
Run Code Online (Sandbox Code Playgroud)

这是运行 Jest 时的控制台输出:

? Candidate Controller › should return …
Run Code Online (Sandbox Code Playgroud)

exception promise typescript jestjs nestjs

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