我正在寻找一种用Jest测试我的NestJs PlayerController的方法。我的控制器和服务声明:
import { QueryBus, CommandBus, EventBus } from '@nestjs/cqrs';
/**
* The service assigned to query the database by means of commands
*/
@Injectable()
export class PlayerService {
/**
* Ctor
* @param queryBus
*/
constructor(
private readonly queryBus: QueryBus,
private readonly commandBus: CommandBus,
private readonly eventBus: EventBus
) { }
@Controller('player')
@ApiUseTags('player')
export class PlayerController {
/**
* Ctor
* @param playerService
*/
constructor(private readonly playerService: PlayerService) { }
我的测试:
describe('Player Controller', () => {
let controller: PlayerController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [PlayerService, CqrsModule],
controllers: [PlayerController],
providers: [
PlayerService,
],
}).compile();
controller = module.get<PlayerController>(PlayerController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
...
Nest无法解析PlayerService的依赖项(?,CommandBus,EventBus)。请确保在PlayerService上下文中索引[0]处的参数可用。
at Injector.lookupComponentInExports (../node_modules/@nestjs/core/injector/injector.js:180:19)
有什么方法可以解决此依赖性问题?
达令说
翻过高山走不出你
相关分类