【问题标题】:Module to use jest as chai expect style?使用 jest 作为 chai 期望样式的模块?
【发布时间】:2020-05-12 17:55:58
【问题描述】:

我是jest 的新手,之前我使用的是chai + mocha。我喜欢使用chaiexpect 风格。 是否有任何 nodejs 模块可以让我像 chai 风格一样编写 jest

我想要expect(isOPDSAgent(ua)).to.be.ok; 而不是expect(isOPDSAgent(ua)).to.be.ok;,这样可以轻松切换旧的单元测试。

我尝试搜索,但找不到。任何帮助表示赞赏!

【问题讨论】:

  • 我试图通过缩短磁贴、更正拼写错误和一些语言润色来使您的问题更具可读性。希望对您有所帮助。

标签: javascript node.js typescript jestjs chai


【解决方案1】:

开玩笑支持setupFiles,你应该可以

package.json
{
  // ...
  "devDependencies": {
    "jest": // ...
    "chai": // ...
  },
  "jest": {
    "setupFiles": [
      "<rootDir>/setupChai.js"
    ]
  }
}
setupChai.js
// this should overwrite the global expect provided by jest
global.expect = require('chai').expect

【讨论】:

  • 我不是说使用 chai,只是 stynx 跟随 chai
猜你喜欢
  • 1970-01-01
  • 2021-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多