我希望你能帮助我。\n我正在使用 Nx 和最新的 Angular/nestjs(日期:2 月 26 日)
\n ...\n "@nestjs/common": "^7.0.0",\n "@nestjs/config": "^0.6.3",\n "@nestjs/core": "^7.0.0",\n "@nestjs/platform-express": "^7.0.0",\n "@nestjs/platform-socket.io": "^7.6.7",\n "@nestjs/websockets": "^7.6.7",\n "jest": "26.2.2",\n "@nrwl/jest": "11.4.0",\n ...\nRun Code Online (Sandbox Code Playgroud)\n我无法使用 NestJS 和 Jest 运行单元测试\n我想测试以下服务:
\n@Injectable()\nexport class CoreApiService {\n logger = new Logger('CoreApiService');\n apiEndpoint;\n\n constructor(private httpService: HttpService, configService: ConfigService) {\n this.apiEndpoint = configService.get('API_SERVICE_ENDPOINT');\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n我收到以下错误:
\nTypeError: Cannot read property 'get' of undefined\n\nRun Code Online (Sandbox Code Playgroud)\n所以看起来 ConfigService (还有 httpService)总是未定义的。
\n当记录 httpService 和 ConfigService 时,它始终是未定义的。\n即使当我尝试实例化新实例时,new CoreApiService(new HttpService(), new ConfigService())\n我什至尝试过类似new …