Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Re-use same components in tests
  • Loading branch information
smvv committed Aug 19, 2020
commit 917a139c3d61132464d69fb8f8539ab38becc755
34 changes: 9 additions & 25 deletions packages/react-router/__tests__/Routes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import { create as createTestRenderer } from 'react-test-renderer';
import { MemoryRouter as Router, Routes, Route } from 'react-router';

describe('A <Routes>', () => {
it('renders the first route that matches the URL', () => {
function Home() {
return <h1>Home</h1>;
}
function Home() {
return <h1>Home</h1>;
}

function Admin() {
return <h1>Admin</h1>;
}

it('renders the first route that matches the URL', () => {
let renderer = createTestRenderer(
<Router initialEntries={['/']}>
<Routes>
Expand All @@ -20,19 +24,11 @@ describe('A <Routes>', () => {
});

it('does not render a 2nd route that also matches the URL', () => {
function Home() {
return <h1>Home</h1>;
}

function Dashboard() {
return <h1>Dashboard</h1>;
}

let renderer = createTestRenderer(
<Router initialEntries={['/home']}>
<Routes>
<Route path="/home" element={<Home />} />
<Route path="/home" element={<Dashboard />} />
<Route path="/home" element={<Admin />} />
</Routes>
</Router>
);
Expand All @@ -41,10 +37,6 @@ describe('A <Routes>', () => {
});

it('renders with non-element children', () => {
function Home() {
return <h1>Home</h1>;
}

let renderer = createTestRenderer(
<Router initialEntries={['/']}>
<Routes>
Expand All @@ -59,14 +51,6 @@ describe('A <Routes>', () => {
});

it('renders with React.Fragment children', () => {
function Home() {
return <h1>Home</h1>;
}

function Admin() {
return <h1>Admin</h1>;
}

let renderer = createTestRenderer(
<Router initialEntries={['/admin']}>
<Routes>
Expand Down
16 changes: 8 additions & 8 deletions packages/react-router/__tests__/useRoutes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { create as createTestRenderer } from 'react-test-renderer';
import { MemoryRouter as Router, useRoutes } from 'react-router';

describe('useRoutes', () => {
function Home() {
return <h1>Home</h1>;
}

function About() {
return <h1>About</h1>;
}

it('returns the matching element from a route config', () => {
function RoutesRenderer({ routes }) {
return useRoutes(routes);
}

function Home() {
return <h1>Home</h1>;
}

function About() {
return <h1>About</h1>;
}

let routes = [
{ path: 'home', element: <Home /> },
{ path: 'about', element: <About /> }
Expand Down