首页 > 解决方案 > @expo/vector-icons 玩笑失败了

问题描述

我有一个包含@expo/vector-icons该组件的组件,该组件正在运行,但开玩笑地失败了。注释掉图标时测试成功

错误信息

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

测试组件.tsx

import React from "react";
import { Ionicons } from "@expo/vector-icons"
import { View } from "react-native"

const TestComponent = () => {
    return(
        <View>
           <Ionicons />
        </View>
    )
}

export default TestComponent

测试组件.test.tsx

import React from 'react';
import TestComponent from '../../components/TestComponent';
import { render } from '@testing-library/react-native';

describe('test FacebookIcon component', () => {
  it('renders correctly', () => {
    const tree = render(<TestComponent />);
    expect(tree).toMatchSnapshot();
  });
});

包.json

"@expo/vector-icons": "^12.0.5",
"expo": "^42.0.0",
"react": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",
"@testing-library/react-native": "^7.1.0",

标签: react-nativejestjsexpo

解决方案


推荐阅读