跳转至主内容
版本:29.7

迁移到Jest

如果你想将已有的代码库迁移到 Jest ,下面有几种迁移的方案:

  • If you are using Jasmine, or a Jasmine like API (for example Mocha), Jest should be mostly compatible, which makes it less complicated to migrate to.
  • 如果你正在使用 AVA, Expect.js (by Automattic), Jasmine, Mocha, proxyquire, Should.js 或 Tape,你可以使用 Jest Codemods 完成自动迁移(见下文)
  • If you like chai, you can upgrade to Jest and continue using chai. 然而,我们建议你尝试 Jest 的断言及其失败的报错信息。 Jest Codemods可以帮助你从 chai 完成迁移(见下文)。

jest-codemods

If you are using AVA, Chai, Expect.js (by Automattic), Jasmine, Mocha, proxyquire, Should.js, Tape, or Sinon you can use the third-party jest-codemods to do most of the dirty migration work. It runs a code transformation on your codebase using jscodeshift.

要转换现有的测试,需要在包含测试的项目中运行:

npx jest-codemods

More information can be found at https://github.com/skovhus/jest-codemods.