Open joyfuI opened 3 years ago
If I add noInitialPop
on the <ConnectedRouter />
, I found the location
would be changed after execute history.push
. But I don't know whether this is a correct way to write test like this.
const App = () => {
const localtion = useLocation();
// without 'noInitialPop', the location's pathname would be alway equal to '/'
// with 'noInitialPop', the location's pathname would be equal to '/another-path'
console.log(location);
}
test('location should be changed', () => {
// After add noInitialPop this push would be trigger
browserHistory.push('/another-path');
render(
<Provider store={store}>
<ConnectedRouter history={browserHistory} noInitialPop>
<App />
</ConnectedRouter>
</Provider>
)
})
For reference, I just found this link to explain about the noInitialPop
I used history.push() to test rendering in a specific location, but the location did not move the rendering result.
When I output the history object to the log, it was confirmed that it returned to the first location after moving to the location.
If you use react-router-dom's
<Router>
instead of<ConnectedRouter>
, this doesn't happen.What's the problem? Here is an example code.
https://codesandbox.io/s/connected-react-router-2-x9dng