1
テストケースにマウントしたいreduxコンテナがあります。それは反応ルータリンクを使用しているコンポーネントを持っています。コンテナをマウント私の歴史に定義されていないエラーを投げていた、このhttps://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/guides/testing.mdを読んだ後、私は今、歴史エラーがなくなっているが、私は次のようなエラーになっています、MemoryRouterを実装:MemoryRouter TypeError:未定義のプロパティ 'pathname'を読み取ることができません
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');
});
を
マイコンポーネント:
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;
ええ、そうです、私のURLは未定義です。ありがとうございました :) –