Reputation: 753
When passing test code with ci while creating a program with nest.js
I got this error
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()
})
})
Controller has similar code
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()
})
})
I don't know why controller and service are responsible for undefind. I'm glad if anyone can tell me. Thank you
Upvotes: 6
Views: 7396
Reputation: 753
Just didn't use anything that depended
providers: [
{
provide: ProfilesService,
useValue: {},
},
]
providers: [
ProfilesService,
{
provide: getRepositoryToken(PatientProfile),
useValue: {},
},
],
thanks
Upvotes: 5