简体   繁体   中英

Module to use jest as chai expect style?

I am new to jest , and I am using chai + mocha at before. I like to use chai 's expect style. Is there any nodejs module which allows me to write jest like chai style?

Instead expect(isOPDSAgent(ua)).toBeTruthy(); I would like to have expect(isOPDSAgent(ua)).to.be.ok; which will make it easy to switch old unit tests.

I tried searching, but can't find it. Any help is appreciated!

jest supports setupFiles and you should be able to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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