Nest无法解析(?)的依存关系。请确保参数[PatientProfileRepository]位于索引[0]

问题描述 投票:0回答:1

背景

[在使用nest.js创建程序时通过ci传递测试代码时

我收到此错误

expect(received).toBeDefined()

Received: undefined


Nest can't resolve dependencies of the ProfilesService (?). Please make sure that the argument PatientProfileRepository at index [0] is available in the RootTestModule context.

问题,未知点

describe('ProfilesService', () => {
  let service: ProfilesService

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      providers: [ProfilesService],
    }).compile()

    service = module.get<ProfilesService>(ProfilesService)
  })

  it('should be defined', () => {
    expect(service).toBeDefined()
  })
})

控制器具有类似的代码

import { Test, TestingModule } from '@nestjs/testing'
import ProfilesController from './profiles.controller'

describe('Profiles Controller', () => {
  let controller: ProfilesController

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      controllers: [ProfilesController],
    }).compile()

    controller = module.get<ProfilesController>(ProfilesController)
  })

  it('should be defined', () => {
    expect(controller).toBeDefined()
  })
})

我不知道为什么控制器和服务负责未定义。我很高兴有人能告诉我。谢谢

typescript testing nest
1个回答
0
投票
只是不使用任何依赖项
© www.soinside.com 2019 - 2024. All rights reserved.