May 2019
Intermediate to advanced
496 pages
10h 38m
English
A Switch component lists a number of routes, only one of which will be rendered at a time. The last Route listed in a Switch will be the one used if nothing else matches, just as a switch statement in most programming languages makes the last clause its default clause.
Here's a test to verify that the last route renders what we expect. The name of the test is important; it explicitly mentions that this is the default route:
it('renders the MainScreen as the default route', () => { render(<App />); const routes = childRoutes(); const lastRoute = routes[routes.length - 1]; expect(lastRoute.props.component).toEqual(MainScreen);});
The test succinctly encodes the notion of a default route into our tests, which is useful ...
Read now
Unlock full access