- Notifications
You must be signed in to change notification settings - Fork 736
Open
Description
the first example of example-react-router fails
to be more precise
test('full app rendering/navigating', () => { const history = createMemoryHistory() render( <Router history={history}> <App /> </Router>, ) // verify page content for expected route // often you'd use a data-testid or role query, but this is also possible expect(screen.getByText(/you are home/i)).toBeInTheDocument() const leftClick = {button: 0} userEvent.click(screen.getByText(/about/i), leftClick) // check that the content changed to the new page expect(screen.getByText(/you are on the about page/i)).toBeInTheDocument() })To Reproduce Steps to reproduce the behavior:
- copy paste the app.test.js from here
- run tests
Expected behavior All three test cases should pass
However I could resolve the error by rendering the App component like this
test('full app rendering/navigating', () => { // const history = createMemoryHistory(); // history.push('/about'); render(<App />, { wrapper: MemoryRouter }); // verify page content for expected route // often you'd use a data-testid or role query, but this is also possible // verify page content for expected route // often you'd use a data-testid or role query, but this is also possible expect(screen.getByText(/you are home/i)).toBeInTheDocument(); const leftClick = { button: 0 }; userEvent.click(screen.getByText(/about/i), leftClick); // check that the content changed to the new page expect(screen.getByText(/you are on the about page/i)).toBeInTheDocument(); });Metadata
Metadata
Assignees
Labels
No labels

