Nest can't resolve dependencies of the ElasticsearchService (?). Please make sure that the argument at index [0] is available in the ElasticsearchModule context.
在测试模块中创建ElasticSearchService
import { Test, TestingModule } from '@nestjs/testing';
import { RepliesController } from './replies.controller';
import { ElasticsearchService, ElasticsearchModule } from '@nestjs/elasticsearch';
import { Client } from 'elasticsearch';
describe('Replies Controller', () => {
let module: TestingModule;
let elasticsearch: ElasticsearchService;
beforeAll(async () => {
module = await Test.createTestingModule({
imports: [ElasticsearchModule],
controllers: [RepliesController],
components: [ElasticsearchService, {provide: Client, useValue: {}}],
}).compile();
elasticsearch = module.get<ElasticsearchService>(ElasticsearchService);
});
it('should be defined', () => {
const controller: RepliesController = module.get<RepliesController>(RepliesController);
expect(controller).toBeDefined();
});
});
[Nest Information]
elasticsearch version : 0.1.2
common version : 5.4.0
core version : 5.4.0
答案 0 :(得分:1)
您需要使用测试模块公开的方法覆盖提供程序,而不是在components数组中进行设置:
Interval(HH:mi:ss)
0:4:23
696:1:36
696:4:51
8760:1:18
There are examples of this in the NestJs docs in the testing section.