Skip to content

The first test of example-react-router fails #897

Open
@FahadAminShovon

Description

@FahadAminShovon

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:

  1. copy paste the app.test.js from here
  2. run tests

Expected behavior All three test cases should pass

Screenshots
Screenshot 2021-07-24 at 5 50 00 PM

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

Screenshot 2021-07-24 at 5 53 18 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions