[任何存在的模块都可以让我使用jest作为柴期望样式吗?

问题描述 投票:0回答:1

jest的新功能,我之前使用chai + mocha

我喜欢使用柴expect风格。

所以有没有存在的nodejs模块可以让我像柴风格一样开玩笑?

我想使expect(isOPDSAgent(ua)).toBeTruthy();变成expect(isOPDSAgent(ua)).to.be.ok;

这将使切换旧单元测试变得容易

我尝试在npm中搜索jest + chai,但找不到它

javascript node.js typescript jestjs chai
1个回答
0
投票

玩笑支持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
© www.soinside.com 2019 - 2024. All rights reserved.