jeudi 5 mars 2020

Nest can't resolve dependencies of the (?). Please make sure that the argument PatientProfileRepository at index [0]

background

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.

Problems, unknown points

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

Aucun commentaire:

Enregistrer un commentaire