Jest版本:16.0.1
当我将导入名称从myComp
更改为MyComp
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;。