Javascript MemoryOuter类型错误:无法读取属性';路径名';未定义的
我有一个redux容器,我想把它安装在我的测试用例中。它有一个使用react路由器链路的组件。装载容器时抛出“历史未定义”错误,在读取此错误后,我实现了MemoryRouter,现在历史错误消失,但我得到以下错误:Javascript MemoryOuter类型错误:无法读取属性';路径名';未定义的,javascript,reactjs,react-router,react-redux,enzyme,Javascript,Reactjs,React Router,React Redux,Enzyme,我有一个redux容器,我想把它安装在我的测试用例中。它有一个使用react路由器链路的组件。装载容器时抛出“历史未定义”错误,在读取此错误后,我实现了MemoryRouter,现在历史错误消失,但我得到以下错误: TypeError: Cannot read property 'pathname' of undefined at Object.createPath (node_modules/history/PathUtils.js:47:26) at Link.ren
TypeError: Cannot read property 'pathname' of undefined
at Object.createPath (node_modules/history/PathUtils.js:47:26)
at Link.render (node_modules/react-router-dom/Link.js:76:44)
我的测试用例:
it('should load popup component', () => {
const container = mount(
<Provider store={ store }>
<MemoryRouter initialIndex='2' initialEntries={ ['/', 'home'] } >
<HomeContainer />
</MemoryRouter>
</Provider>
);
assert.equal(container.find('PopUp').length, 1, 'Popup component is not mounted');
});
此错误是因为您的
,请确保to
值有效且未定义/为空。是的,您是对的,我的URL未定义。谢谢:)这救了我一天。谢谢
class Home extends Component {
componentWillMount() {
this.props.init();
}
componentDidMount() {
document.title = 'Home';
}
render() {
return (
<div>
<Popup />
</div>
);
}
}
export default Home;
const mapStateToProps = state => ({
data: state.mainReducer.data
});
const HomeContainer = connect(mapStateToProps, { init })(Home);
export default HomeContainer;