From the course: Testing in React with Vitest

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Testing the app routes

Testing the app routes

- [Instructor] In this video, we'll write our tests to ensure our router renders the respective pages. Now, we have a component that handles unknown routes. We'll use the asterisk to tell React Router to hit this route when we have no router listed, no such router listed in our routes. Now, if we try opening a random route, we see the app redirects us to the Not Found page. Find this chapter's starting code in the link below. So far, we've been able to add routing to our application, navigate to different pages, and get it directed back to our main page. Now, let's write this test. Under our Renders hello world test, let's create another test and call it Renders not found if path is invalid. If we open an example given by testing library, we see they give us helpful code to document how we can get started, and in the test, they use a memory router. A memory router is a useful tool by React Router that helps render multiple paths and check contents if or not they exist. We pass an…

Contents