Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location cannot be moved in testing-library #533

Open
joyfuI opened this issue Aug 12, 2021 · 1 comment
Open

Location cannot be moved in testing-library #533

joyfuI opened this issue Aug 12, 2021 · 1 comment

Comments

@joyfuI
Copy link

joyfuI commented Aug 12, 2021

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

@john-pimq
Copy link

john-pimq commented Mar 18, 2022

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.

App.js

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);
}

App.test.jsx

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants