在使用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()
})
})
我不知道为什么控制器和服务负责未定义。 我很高兴有人可以告诉我。 谢谢
答案 0 :(得分:1)
只是没有使用任何依赖的东西
providers: [
{
provide: ProfilesService,
useValue: {},
},
]
providers: [
ProfilesService,
{
provide: getRepositoryToken(PatientProfile),
useValue: {},
},
],
谢谢