小编the*_*ire的帖子

Nest.js 单元测试中的模拟注入服务

我想测试我的服务(位置服务)。在此位置服务中,我注入存储库和其他名为 GeoLocationService 的服务,但当我尝试模拟此 GeoLocationService 时陷入困境。

\n

它给我一个错误

\n
GeolocationService \xe2\x80\xba should be defined\n\n    Nest can't resolve dependencies of the GeolocationService (?). Please make sure that the argument HttpService at index [0] is available in the RootTestModule context.\n\n
Run Code Online (Sandbox Code Playgroud)\n

这是提供商的代码

\n
@Injectable()\nexport class LocationService {\n  constructor(\n    @Inject('LOCATION_REPOSITORY')\n    private locationRepository: Repository<Location>,\n\n    private geolocationService: GeolocationService, // this is actually what I ma trying to mock\n  ) {}\n\n  async getAllLocations(): Promise<Object> {\nreturn await this.locationRepository.find()\n  }\n....\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n

这是测试代码

\n
describe('LocationService', () => {\n  let service: …
Run Code Online (Sandbox Code Playgroud)

node.js jestjs nestjs

10
推荐指数
1
解决办法
2万
查看次数

如何在Nestjs中扩展多个dto类

我是新手nest.js,对此有疑问。

我想将多个类扩展Dto到我的主dto类,但我知道不可能扩展超过 2 个dto类。你知道该怎么做吗?

这是我的主要dto课程:

export class CarDto extends PickupLocationDto {
  @ApiProperty({ example: 'Aventador', description: 'The car name' })
  readonly modelName: string;
}
Run Code Online (Sandbox Code Playgroud)

最近我只能从PickupLocationDto类中扩展它,但我想再扩展一个dto类到这个CarDto类。

任何帮助表示赞赏。

javascript node.js typescript nestjs

3
推荐指数
1
解决办法
8022
查看次数

标签 统计

nestjs ×2

node.js ×2

javascript ×1

jestjs ×1

typescript ×1