【问题标题】:How to create test data using Drivine and NestJS?如何使用 Drivine 和 NestJS 创建测试数据?
【发布时间】:2023-01-26 03:21:54
【问题描述】:

在存储库的实现中,您使用 @InjectPersistenceManager() 注入 PersistenceManager 接口。对于测试,docs 提到使用 RunWithDrivine,并将 Drivine(通过 AppModule)导入到 createTestingModule 调用中。这允许将 PersistenceManager 注入到要使用的存储库中。

我创建了一个带有新 Neo4j 数据库的临时 Docker 容器供测试使用(使用名为 testcontainers 的包)。该数据库需要一些数据才能使用。在测试设置中,可以通过使用装饰器通常提供的字符串从测试模块中检索它来获取 PersistenceManagerapp.get("PersistenceManager:default") as PersistenceManager,但这显然不是正确的方法。
我如何让PersistenceManager 设置数据(并做其他事情)?

【问题讨论】:

    标签: neo4j nestjs drivine


    【解决方案1】:

    app.get("PersistenceManager:default") as PersistenceManager

    这实际上可能是您想要做的,但需要将 { strict: false } 作为第二个参数添加到 get 方法。看到 @InjectPersistenceManager() 只是 @Inject('PersistenceManager:database')database 默认情况下是 default,你有正确的令牌,所以你可能只需要告诉 Nest 比顶级模块更深入,因此 { strict: false } 选项

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-17
      • 2019-09-20
      • 2022-08-23
      • 2019-12-28
      • 2020-09-24
      • 2011-05-16
      相关资源
      最近更新 更多