【问题标题】:how not to have trouble creating the same user again when testing [closed]测试时如何避免再次创建相同的用户[关闭]
【发布时间】:2021-10-09 14:56:58
【问题描述】:

当我测试两次创建用户的功能时,我遇到了一个错误,即我再次创建了相同的用户。 有什么方法可以让我创建用户只是为了测试并在测试结束时自动删除它?我正在使用 mongo 和猫鼬。我知道我可以在测试开始时创建删除用户的功能,但我知道这不是一个好习惯my code with the log of error that user already exists

【问题讨论】:

    标签: javascript node.js mongodb mongoose jestjs


    【解决方案1】:

    使用 beforeEach 和 afterEach(或 beforeAll 和 afterAll)块。

    https://jestjs.io/docs/setup-teardown

    【讨论】:

      猜你喜欢
      • 2023-04-04
      • 2011-07-02
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多