在导入

时间:2016-10-16 14:27:35

标签: reactjs react-native jestjs jsx

Jest版本:16.0.1

当我将导入名称从myComp更改为MyComp

时,有人可以告诉我为什么此Jest测试会引发错误

Home.test.js

import renderer from 'react-test-renderer';
import { Home } from './Home.js';
import React from 'react';

describe('Link', () => {
  it('should render correctly', () => {
    const component = renderer.create(
      <Home />
    );
    expect(component.toJSON()).toMatchSnapshot();
  });
});

Home.js

import React from 'react';
import { default as myComp } from './MyComp';
import { View } from 'react-native';

export function Home() {
  return (
    <View>
      <myComp />
    </View>
  );
}

export default Home;

MyComp.js

import React from 'react';
import { connect } from 'react-redux';
import { Text } from 'react-native';

class MyComp extends React.Component {
  render() {
    return (
      <Text>hello there</Text>
    );
  }
}

MyComp.propTypes = {};

export default connect()(MyComp);

我将Home.js的导入... default as myComp...更改为...default as MyComp时收到的错误

不变违规:找不到&#34;存储&#34;在&#34; Connect(MyComp)&#34;的上下文或道具中。将根组件包装在<Provider>中,或明确传递&#34;存储&#34;作为&#34; Connect(MyComp)&#34;。

的道具

0 个答案:

没有答案