【问题标题】:error jest: Warning: React.createElement: type is invalid错误笑话:警告:React.createElement:类型无效
【发布时间】:2019-11-03 12:08:13
【问题描述】:

我正在使用 Typescript 测试一个 React Native 应用程序构建。

笑话输出:

Invariant Violation:元素类型无效:期望字符串(对于内置组件)或类/函数(对于复合组件)但得到:对象

附言。无论如何,Rn 工作也呈现方法,但我不明白代码中的这个错误在哪里。谁能帮帮我?

App.test.tsx

import 'react-native';
import * as React from 'react';
import App from '../App';

import renderer from 'react-test-renderer';

it('renders correctly', () => {
  renderer.create(<App />);
});

【问题讨论】:

    标签: react-native jestjs


    【解决方案1】:

    在这里找到解决方案: Why is my jest test failing in React native with typescript?

    如果您在 expo 中使用 react-native,请将其添加到您的 package.json:

    "jest": {
        "preset": "jest-expo",
        "moduleFileExtensions": [
            "ts",
            "tsx",
            "js"
        ]
    },
    

    【讨论】:

      猜你喜欢
      • 2018-07-22
      • 1970-01-01
      • 2022-12-12
      • 2020-12-24
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      • 2018-04-28
      • 2020-04-25
      相关资源
      最近更新 更多