相关疑难解决方法(0)

如何让 jest 使用与 create-react-app 上的 react-script 测试相同的配置运行?

我知道我可以运行npm testwhichreact-script test并且它可以工作,它成功地运行了测试。但我有兴趣弄清楚如何使用jest相同的配置直接运行react-script。希望不必复制配置或弹出应用程序。我开始阅读的源代码,react-scripts但到目前为止我无法弄清楚。

想要这个的原因是:

  • 我的 CRA 项目是一个更大项目的一部分,我可以jest在顶层运行并运行所有测试。
  • 在 WebStorm 中,我可以利用 Jest 集成,其中包括:
    • 显示运行时通过或失败的测试列表。
    • 能够运行单独的测试。
    • 做代码覆盖。

如果我jest在我的 CRA 应用程序上运行,我会收到此错误:

PS C:\Users\pupeno\Documents\Flexpoint Tech\js\exp7\frontend> jest
 FAIL  src/App.test.tsx
  ? Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use …
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs create-react-app

4
推荐指数
1
解决办法
2195
查看次数

标签 统计

create-react-app ×1

jestjs ×1

reactjs ×1