You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从@testing-library/react导入screen时ESLint报错求助

导入@testing-library/react的screen时ESLint报错问题

ESLint报错信息:

ESLint: screen not found in '@testing-library/react'(import/named)

导入代码如下(render导入正常):

// render导入正常
import { render, screen } from '@testing-library/react';

测试可正常运行且全部通过,但Typescript ESLint仍显示红色错误标识。

尝试在tsconfig中添加以下配置,但未解决问题:

{
  "compilerOptions": {
    ...,
    "types": ["@testing-library/react"]
  },
  ...
}

更新[2022-08-25]:我同时使用了eslint-plugin-testing-library,相关配置如下:

extends: [..., 'plugin:testing-library/react'],
  plugins: [..., 'testing-library'],

内容的提问来源于stack exchange,提问作者RickCardoso

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 16:48:24