【发布时间】:2020-06-03 09:42:18
【问题描述】:
我正在尝试从 NestJS 中的测试模块中检索提供程序,但在使用接口从模块中提供该模块时无法解析该模块。
这是我目前所拥有的:
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile()
...
const fooService = moduleFixture.get<FooService>(FooService) // Nest could not find FooService element
当导出 FooService 的模块正在做这样的事情时......
@Global()
@Module({
providers: [{ provide: 'IFooService', useClass: FooService }],
exports: [{ provide: 'IFooService', useClass: FooService }],
})
export class FooModule {}
如何让 FooService 实例能够直接调用方法?
【问题讨论】:
标签: unit-testing testing nestjs