【发布时间】:2019-07-18 08:08:20
【问题描述】:
在另一个文件中我已经像这样导入但是当我在测试中使用时出现错误 React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for复合组件)但得到:未定义。您可能忘记从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。可以是什么?
import { RateComponent, mapStateToProps } from '../components/Rate';
it ('renders correctly if has data', () => {
const tree = shallow( <RateComponent dispatch={jest.fn()}/>);
expect(tree).toMatchSnapshot();
});
这就是我的导出方式。
export
{
RateComponent,
mapStateToProps
}
export default connect(mapStateToProps)(RateComponent);
【问题讨论】: