繁体   English   中英

使用 jest 作为 chai 期望风格的模块?

[英]Module to use jest as chai expect style?

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

相反, expect(isOPDSAgent(ua)).toBeTruthy(); 我想要expect(isOPDSAgent(ua)).to.be.ok; 这将使切换旧的单元测试变得容易。

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

jest 支持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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM