【问题标题】:Getting error while adding React Testing Library for create-react-app (version 16.12.0)为 create-react-app 添加 React 测试库时出错(版本 16.12.0)
【发布时间】:2022-01-23 06:28:32
【问题描述】:

我正在使用 typescript 开发一个 react 项目(react 版本 16.12.0),我想在其中添加 React 测试库。较新版本的 react 带有 React-Testing-Library,但我正在处理的项目不带有 RTL,所以我手动安装了它。

我将以下内容添加到 package.json 并安装了 yarn

"@types/testing-library__react": "^10.2.0",

当我启动纱线时,我在下面得到这个错误

使用的其他相关包版本

 "@types/react": "~16.9.14",

 "typescript": "3.4.5",

 "react-scripts": "^3.0.0",

【问题讨论】:

    标签: reactjs typescript unit-testing react-testing-library react-testing


    【解决方案1】:

    打字稿版本出现问题。经过一番研究,我发现要让 react-testing-library 与typescript 一起工作,需要将 TS 版本更新到 3.8 及以上。

    在将typescript 版本更新为3.8 并修复此更新导致的一些错误后,我能够解决此错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-23
      • 1970-01-01
      • 2020-11-13
      • 1970-01-01
      • 2022-01-19
      • 2018-12-04
      • 1970-01-01
      相关资源
      最近更新 更多