testing-library / testing-library/testing-library-docs
The first test of example-react-router fails
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 479
- Forks
- 740
- PR merge metrics
- No merged PRs in 30d
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
Screenshots

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();
});
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the example-react-router page and the app.test.js copied from its linked documentation example. Run the example's tests to reproduce the first failure, then compare the Router and MemoryRouter variants shown in the issue. Done means all three test cases pass using the documented example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- documentation, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100