NodeJS HttpService在使用NestJS应用程序的e2e测试中不工作

tct7dpnv  于 2022-11-22  发布在  Node.js
关注(0)|答案(1)|浏览(164)

我正在尝试为我的控制器实现e2e测试,但无法使HttpService工作。我正在将HttpModule导入测试模块,但它没有看到它。
代码:

const module = await Test.createTestingModule({
      imports: [HttpModule],
      controllers: [AuthenticationController],
      providers: [
        UsersService,
        AuthenticationService,
        {
          provide: getModelToken(User.name),
          useValue: usersRepository,
        },
      ],
    }).compile();

`
错误:

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

    Potential solutions:
    - If AXIOS_INSTANCE_TOKEN is a provider, is it part of the current RootTestModule?
    - If AXIOS_INSTANCE_TOKEN is exported from a separate @Module, is that module imported within RootTestModule?
      @Module({
        imports: [ /* the Module containing AXIOS_INSTANCE_TOKEN */ ]
      })

也许以前有人解决过这样的错误,可以给点建议吗?谢谢。
我试着在网上找一些解决办法,但一无所获

atmip9wb

atmip9wb1#

不知道为什么,当我这样注射时,它就开始起作用了:

{
  provide: HttpService,
  useValue: new HttpService(),
},

相关问题