小编Den*_*nis的帖子

React.jsx:使用 Jest 和 React 测试库使用 svg 测试 React 组件时,类型无效

我有一个 Next.js 12.1.4 项目,使用 Typescript、React 测试库和 SVGR 来导入如下图标:import ChevronLeftIcon from './chevron-left.svg'

我遇到的问题是,当我运行包含 SVG 导入的组件测试时,出现以下错误:

console.error
    Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.
    
    Check the render method of `Loader`.
        at Loader (.../src/components/atoms/Loader/Loader.tsx:11:36)
        at div
        at button
        at Button (.../src/components/atoms/buttons/Button/Button.tsx:19:5)

      15 |         }`}
      16 |     >
    > 17 |         <LoaderIcon />
         |                       ^
      18 |     </div>
      19 | )
      20 |

      at printWarning (node_modules/react/cjs/react-jsx-runtime.development.js:117:30)
      at error (node_modules/react/cjs/react-jsx-runtime.development.js:93:5) …
Run Code Online (Sandbox Code Playgroud)

svg typescript jestjs next.js

2
推荐指数
1
解决办法
2381
查看次数

标签 统计

jestjs ×1

next.js ×1

svg ×1

typescript ×1