Skip to main content

Mobile development · Intermediate · 24 min

Set up the Larkfield Clinic booking app with Expo Router tabs and stacks

By Padding · Updated 18 Nov 2026
Expo SDK 58 · expo-router 58.0 · React Native 0.88.1 · Node.js 26 (node:26 image)

You will have the Larkfield Clinic booking app running in Expo SDK 58, with Book, Appointments and Profile tabs, a Book stack that goes from service to practitioner and time, a typed appointment detail route, shared header styles, in-memory clinic data and a first passing Jest test.

On this page

Larkfield Clinic is the fictional clinic whose booking app was designed in the design series that starts with sketch wireframes on paper. Patients pick a service, then a practitioner and a time, and later check their upcoming appointments. This series builds that app in Expo, one part at a time, until it is ready for the stores.

This first part builds the skeleton every later part hangs from. The Expo Router navigation tutorial stopped at one stack and two tabs. Here you nest navigators: a tab bar at the bottom, a stack of booking screens inside the first tab, and a detail screen that slides over the tabs when a patient opens an appointment. You also give the screens one shared header style, keep the clinic's services and practitioners in a small data module, and finish with a Jest test that renders the real route tree, so the later parts start from a project that is already tested.

Everything lives in ~/larkfield-app-demo. Keep the folder when you finish: part 2 adds the booking form to it, and the last part of the series removes it.

Step 1 · Create the project

Create the app from the SDK 58 default template. Naming the template version means a later SDK release does not change what you get. The first run of npx asks to download create-expo-app; answer y:

Bash
cd ~
npx create-expo-app@5.0.0 larkfield-app-demo --template default@sdk-58

It copies the template, installs the dependencies with npm, and prints the commands to start. Allow a few minutes on a slow connection. On prepaid mobile data, expect a download of a few hundred megabytes; npm caches the packages, so the next project you create is much cheaper.

Check it worked

Bash
cd ~/larkfield-app-demo
node -e "const p = require('./package.json'); console.log(p.dependencies.expo, p.dependencies['expo-router'], p.dependencies['react-native'])"

It prints ~58.1.0 ~58.0.33 0.88.1, or later patch versions of the same lines. Leave these versions to Expo: add libraries with npx expo install, which picks the version that matches SDK 58.

Step 2 · Plan the routes and clear the template

Before writing code, decide what each address shows and which navigator holds it. Expo Router reads the tree of files under src/app. A _layout.tsx file says how the screens in its folder are arranged, a folder in parentheses is a group that shares a layout without adding to the address, and a name in square brackets is a value read from the address.

| File in src/app | Address | What it is |
|---|---|---|
| _layout.tsx | none | the root stack, which holds the tabs and the detail screen |
| index.tsx | / | sends the patient on to /book |
| (tabs)/_layout.tsx | none | the bottom tab bar |
| (tabs)/book/_layout.tsx | none | the stack inside the Book tab |
| (tabs)/book/index.tsx | /book | choose a service |
| (tabs)/book/[serviceId].tsx | /book/checkup | choose a practitioner and a time |
| (tabs)/appointments.tsx | /appointments | upcoming appointments (second tab) |
| (tabs)/profile.tsx | /profile | the patient's profile (third tab) |
| appointments/[id].tsx | /appointments/42 | one appointment, shown over the tabs |
| +not-found.tsx | anything else | a screen for addresses that match nothing |

A tree of the files in src/app beside the navigators they create: the root stack holds the tabs group and the appointment detail screen, and the tabs hold the Book stack, Appointments and Profile
Each layout file creates one navigator. Screens without a layout of their own belong to the nearest one above them.

Two choices are worth a sentence each. The appointment detail lives outside (tabs), in the root stack, so it covers the tab bar: a patient reading one appointment does not need tabs, and the back button returns them to the list. The time screen lives inside the Book stack, so moving from service to time keeps the tab bar visible and the Book tab remembers where the patient was if they switch tabs and come back.

The template has its own screens, components and theme, written for a demo with native tabs. Delete them so that only your files are routes. This removes everything under src, so copy anything you changed in the template first:

Bash
cd ~/larkfield-app-demo
rm -rf src/app src/components src/hooks src/constants src/global.css
mkdir -p "src/app/(tabs)/book" src/app/appointments src/data src/__tests__

Check it worked

Bash
find src -type d | sort

The list is src, src/__tests__, src/app, src/app/(tabs), src/app/(tabs)/book, src/app/appointments and src/data, with no files yet. The quoted heredocs in the next steps keep the brackets and parentheses in these paths safe from the shell.

Step 3 · Add the clinic data and a shared header style

The screens read from two small modules. They stand in for the clinic's API, which arrives in part 4, and they keep each piece of data in one place: the list screen and the detail screen read the same appointment, so they cannot disagree.

Services and practitioners go in src/data/clinic.ts. Each practitioner lists the services they offer and their next free times. The times are fixed labels for now, because there is no server to ask yet:

Bash
cd ~/larkfield-app-demo
cat > src/data/clinic.ts <<'TS'
export type Service = { id: string; name: string; minutes: number; summary: string }
export type Slot = { id: string; label: string }
export type Practitioner = {
  id: string
  name: string
  role: string
  serviceIds: string[]
  slots: Slot[]
}

export const services: Service[] = [
  { id: 'checkup', name: 'General check-up', minutes: 20, summary: 'Blood pressure, weight and a talk about how you feel' },
  { id: 'vaccination', name: 'Vaccination', minutes: 15, summary: 'Routine and travel vaccines' },
  { id: 'antenatal', name: 'Antenatal visit', minutes: 30, summary: 'A pregnancy check with a midwife' },
]

export const practitioners: Practitioner[] = [
  {
    id: 'okafor',
    name: 'Dr Chidi Okafor',
    role: 'General practitioner',
    serviceIds: ['checkup', 'vaccination'],
    slots: [
      { id: 'okafor-1', label: 'Wed 2 Dec, 09:30' },
      { id: 'okafor-2', label: 'Wed 2 Dec, 11:00' },
    ],
  },
  {
    id: 'wanjiru',
    name: 'Nurse Grace Wanjiru',
    role: 'Practice nurse',
    serviceIds: ['vaccination'],
    slots: [
      { id: 'wanjiru-1', label: 'Thu 3 Dec, 10:15' },
      { id: 'wanjiru-2', label: 'Fri 4 Dec, 14:00' },
    ],
  },
  {
    id: 'mensah',
    name: 'Ama Mensah',
    role: 'Midwife',
    serviceIds: ['antenatal', 'checkup'],
    slots: [{ id: 'mensah-1', label: 'Sat 5 Dec, 08:45' }],
  },
]

export function findService(id: string | undefined): Service | undefined {
  return services.find((service) => service.id === id)
}

export function practitionersFor(serviceId: string): Practitioner[] {
  return practitioners.filter((practitioner) => practitioner.serviceIds.includes(serviceId))
}
TS

The patient's booked appointments go in src/data/appointments.ts. Each one stores its start as a UTC time in ISO format, and formatWhen shows it in the phone's own language and time zone, so a patient in Lagos and one in Nairobi each see their local time:

Bash
cat > src/data/appointments.ts <<'TS'
export type Appointment = { id: string; service: string; practitioner: string; startsAt: string }

export const appointments: Appointment[] = [
  { id: '42', service: 'General check-up', practitioner: 'Dr Chidi Okafor', startsAt: '2026-12-02T09:30:00Z' },
  { id: '43', service: 'Vaccination', practitioner: 'Nurse Grace Wanjiru', startsAt: '2026-12-04T14:00:00Z' },
]

export function findAppointment(id: string | undefined): Appointment | undefined {
  return appointments.find((appointment) => appointment.id === id)
}

export function formatWhen(iso: string): string {
  return new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' }).format(new Date(iso))
}
TS

Last, the shared look. Every navigator in the app draws a header, and each one would otherwise pick its own colours. Put the colours and the header options in src/theme.ts, and pass the same object to every layout:

Bash
cat > src/theme.ts <<'TS'
export const colours = {
  ink: '#0b0c0e',
  text: '#2a2d33',
  muted: '#6a707b',
  line: '#d9dce1',
  canvas: '#f1f2f4',
  surface: '#ffffff',
  accent: '#1d5c4d',
}

export const headerOptions = {
  headerStyle: { backgroundColor: colours.surface },
  headerTintColor: colours.ink,
  headerTitleStyle: { fontWeight: '600' as const },
  headerShadowVisible: false,
}
TS

headerTintColor colours the title and the back button. Changing the clinic's colours later means editing this one file.

Check it worked

Bash
ls src/data src/theme.ts
grep -c "id: '" src/data/clinic.ts

The listing shows appointments.ts, clinic.ts and src/theme.ts, and the count is 11: three services, three practitioners and five time slots.

Step 4 · Write the root stack and the tabs

The root layout is a stack with two kinds of screen in it: the whole tab group, and the appointment detail. Create src/app/_layout.tsx:

Bash
cat > src/app/_layout.tsx <<'TSX'
import { Stack } from 'expo-router'

import { headerOptions } from '@/theme'

export const unstable_settings = { anchor: '(tabs)' }

export default function RootLayout() {
  return (
    <Stack screenOptions={headerOptions}>
      <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
      <Stack.Screen name="appointments/[id]" options={{ title: 'Appointment' }} />
      <Stack.Screen name="+not-found" options={{ title: 'Not found' }} />
    </Stack>
  )
}
TSX

The tabs draw their own headers, so the root stack hides its header for (tabs). unstable_settings.anchor matters when a screen is opened straight from a link, such as a reminder notification in part 5 or a text-message link in part 6: Expo Router puts the tabs underneath it in the stack, so the patient gets a back button to the app instead of a dead end. Older guides call this setting initialRouteName; Expo Router 58 still accepts that name but warns that it is deprecated.

Nothing lives at / in the tree, because the Book tab's address is /book. Add src/app/index.tsx, which sends anyone who opens the app's root address on to the Book tab:

Bash
cat > src/app/index.tsx <<'TSX'
import { Redirect } from 'expo-router'

export default function Index() {
  return <Redirect href="/book" />
}
TSX

Now the tab bar, in src/app/(tabs)/_layout.tsx. The Book tab hides the tab header because its own stack draws one, with a back button:

Bash
cat > "src/app/(tabs)/_layout.tsx" <<'TSX'
import { Tabs } from 'expo-router'

import { colours, headerOptions } from '@/theme'

export default function TabLayout() {
  return (
    <Tabs
      screenOptions={{
        ...headerOptions,
        tabBarActiveTintColor: colours.accent,
        tabBarInactiveTintColor: colours.muted,
      }}
    >
      <Tabs.Screen name="book" options={{ title: 'Book', headerShown: false }} />
      <Tabs.Screen name="appointments" options={{ title: 'Appointments' }} />
      <Tabs.Screen name="profile" options={{ title: 'Profile' }} />
    </Tabs>
  )
}
TSX

These are JavaScript tabs, which look the same on iOS, Android and the web and render fully in Jest. The template you deleted used native tabs (expo-router/native-tabs), which draw the platform's own tab bar, including the iOS 26 glass style. You can switch later without moving any screen files; follow iOS and Android conventions in one design covers when the platform look is worth it. Tab icons go in each screen's tabBarIcon option; the labels alone are enough for now.

Finally, the screen for addresses that match nothing, src/app/+not-found.tsx. Links from text messages get mistyped and cut short, so this screen offers a way back:

Bash
cat > "src/app/+not-found.tsx" <<'TSX'
import { Link } from 'expo-router'
import { StyleSheet, Text, View } from 'react-native'

import { colours } from '@/theme'

export default function NotFoundScreen() {
  return (
    <View style={styles.screen}>
      <Text style={styles.title}>We could not find that page.</Text>
      <Link href="/book" style={styles.link}>
        Book an appointment
      </Link>
    </View>
  )
}

const styles = StyleSheet.create({
  screen: { flex: 1, alignItems: 'center', justifyContent: 'center', gap: 12, padding: 24, backgroundColor: colours.canvas },
  title: { fontSize: 18, fontWeight: '600', color: colours.ink },
  link: { fontSize: 16, color: colours.accent, paddingVertical: 12 },
})
TSX

Check it worked

Bash
find src/app -name "*.tsx" | sort

The list has four files: src/app/(tabs)/_layout.tsx, src/app/+not-found.tsx, src/app/_layout.tsx and src/app/index.tsx. The tab layout names three screens that do not exist yet; the next two steps add them.

Step 5 · Build the Book stack

The Book tab gets its own stack, so choosing a time slides in over the service list and the back button returns to it. Create src/app/(tabs)/book/_layout.tsx:

Bash
cat > "src/app/(tabs)/book/_layout.tsx" <<'TSX'
import { Stack } from 'expo-router'

import { headerOptions } from '@/theme'

export default function BookLayout() {
  return (
    <Stack screenOptions={headerOptions}>
      <Stack.Screen name="index" options={{ title: 'Book' }} />
      <Stack.Screen name="[serviceId]" options={{ title: 'Choose a time' }} />
    </Stack>
  )
}
TSX

The first screen lists the services. Each row is a Link to the time screen, with the service's ID in the address. asChild hands the link's behaviour to the Pressable, so the whole card is one tap target:

Bash
cat > "src/app/(tabs)/book/index.tsx" <<'TSX'
import { Link } from 'expo-router'
import { FlatList, Pressable, StyleSheet, Text } from 'react-native'

import { services } from '@/data/clinic'
import { colours } from '@/theme'

export default function ChooseServiceScreen() {
  return (
    <FlatList
      data={services}
      keyExtractor={(service) => service.id}
      style={styles.screen}
      contentContainerStyle={styles.list}
      ListHeaderComponent={<Text style={styles.lead}>What do you need?</Text>}
      renderItem={({ item }) => (
        <Link href={{ pathname: '/book/[serviceId]', params: { serviceId: item.id } }} asChild>
          <Pressable accessibilityRole="link" style={styles.card}>
            <Text style={styles.name}>{item.name}</Text>
            <Text style={styles.meta}>
              {item.minutes} minutes · {item.summary}
            </Text>
          </Pressable>
        </Link>
      )}
    />
  )
}

const styles = StyleSheet.create({
  screen: { backgroundColor: colours.canvas },
  list: { padding: 16, gap: 12 },
  lead: { fontSize: 20, fontWeight: '600', color: colours.ink, marginBottom: 4 },
  card: { padding: 16, gap: 4, borderRadius: 12, backgroundColor: colours.surface, borderWidth: 1, borderColor: colours.line },
  name: { fontSize: 18, fontWeight: '600', color: colours.ink },
  meta: { fontSize: 15, color: colours.text },
})
TSX

The href names the route pattern, /book/[serviceId], and its parameter. The pattern leaves out (tabs), because a group is not part of the address. With typed routes, which the template turns on in app.json under experiments.typedRoutes, your editor flags a pattern that matches no file.

The second screen reads the service from the address, lists the practitioners who offer it, and lets the patient pick a time. Create src/app/(tabs)/book/[serviceId].tsx:

Bash
cat > "src/app/(tabs)/book/[serviceId].tsx" <<'TSX'
import { Stack, useLocalSearchParams } from 'expo-router'
import { useState } from 'react'
import { Pressable, ScrollView, StyleSheet, Text, View } from 'react-native'

import { findService, practitionersFor, type Slot } from '@/data/clinic'
import { colours } from '@/theme'

type Choice = { slot: Slot; practitioner: string }

export default function ChooseTimeScreen() {
  const { serviceId } = useLocalSearchParams<'/book/[serviceId]'>()
  const service = findService(serviceId)
  const [choice, setChoice] = useState<Choice | null>(null)

  if (!service) {
    return (
      <View style={styles.screen}>
        <Stack.Screen options={{ title: 'Not found' }} />
        <Text style={styles.lead}>We do not offer that service.</Text>
      </View>
    )
  }

  return (
    <ScrollView style={styles.scroll} contentContainerStyle={styles.screen}>
      <Stack.Screen options={{ title: service.name }} />
      {practitionersFor(service.id).map((practitioner) => (
        <View key={practitioner.id} style={styles.card}>
          <Text style={styles.name}>{practitioner.name}</Text>
          <Text style={styles.meta}>{practitioner.role}</Text>
          <View style={styles.slots}>
            {practitioner.slots.map((slot) => {
              const selected = choice?.slot.id === slot.id
              return (
                <Pressable
                  key={slot.id}
                  accessibilityRole="button"
                  accessibilityLabel={`${slot.label} with ${practitioner.name}`}
                  accessibilityState={{ selected }}
                  onPress={() => setChoice({ slot, practitioner: practitioner.name })}
                  style={[styles.slot, selected && styles.slotSelected]}
                >
                  <Text style={[styles.slotText, selected && styles.slotTextSelected]}>{slot.label}</Text>
                </Pressable>
              )
            })}
          </View>
        </View>
      ))}
      {choice ? (
        <Text accessibilityLiveRegion="polite" style={styles.lead}>
          You chose {choice.slot.label} with {choice.practitioner}.
        </Text>
      ) : null}
    </ScrollView>
  )
}

const styles = StyleSheet.create({
  scroll: { backgroundColor: colours.canvas },
  screen: { padding: 16, gap: 12 },
  lead: { fontSize: 18, fontWeight: '600', color: colours.ink },
  card: { padding: 16, gap: 8, borderRadius: 12, backgroundColor: colours.surface, borderWidth: 1, borderColor: colours.line },
  name: { fontSize: 18, fontWeight: '600', color: colours.ink },
  meta: { fontSize: 15, color: colours.text },
  slots: { flexDirection: 'row', flexWrap: 'wrap', gap: 8 },
  slot: { minHeight: 44, justifyContent: 'center', paddingHorizontal: 14, borderRadius: 8, borderWidth: 1, borderColor: colours.accent },
  slotSelected: { backgroundColor: colours.accent },
  slotText: { fontSize: 15, color: colours.accent },
  slotTextSelected: { color: colours.surface, fontWeight: '600' },
})
TSX

Three details. useLocalSearchParams<'/book/[serviceId]'>() takes the route itself as its type, so TypeScript knows serviceId is a string without a hand-written type that could drift from the file name. Stack.Screen inside the screen replaces the layout's "Choose a time" title with the service name once it is known. And the ID comes from an address, which anyone can type, so the screen handles one that matches no service.

Each time slot is at least 44 points tall and announces itself as a button with the time and the practitioner's name, so a screen reader user hears "Wed 2 Dec, 09:30 with Dr Chidi Okafor" rather than a bare time. Choosing a slot shows a confirmation line for now; in part 2 the same tap opens the booking details form.

Check it worked

Bash
grep -n "useLocalSearchParams<'/book/\[serviceId\]'>" "src/app/(tabs)/book/[serviceId].tsx"

It prints the line with the typed hook. The screens appear on a device in the step after next.

Step 6 · Add the Appointments, Profile and detail screens

The second tab lists the appointments. Each row links to /appointments/[id], which lives in the root stack, so it opens over the tab bar:

Bash
cat > "src/app/(tabs)/appointments.tsx" <<'TSX'
import { Link } from 'expo-router'
import { FlatList, Pressable, StyleSheet, Text } from 'react-native'

import { appointments, formatWhen } from '@/data/appointments'
import { colours } from '@/theme'

export default function AppointmentsScreen() {
  return (
    <FlatList
      data={appointments}
      keyExtractor={(appointment) => appointment.id}
      style={styles.screen}
      contentContainerStyle={styles.list}
      ListEmptyComponent={<Text style={styles.meta}>You have no upcoming appointments.</Text>}
      renderItem={({ item }) => (
        <Link href={{ pathname: '/appointments/[id]', params: { id: item.id } }} asChild>
          <Pressable accessibilityRole="link" style={styles.card}>
            <Text style={styles.name}>{item.service}</Text>
            <Text style={styles.meta}>
              {item.practitioner} · {formatWhen(item.startsAt)}
            </Text>
          </Pressable>
        </Link>
      )}
    />
  )
}

const styles = StyleSheet.create({
  screen: { backgroundColor: colours.canvas },
  list: { padding: 16, gap: 12 },
  card: { padding: 16, gap: 4, borderRadius: 12, backgroundColor: colours.surface, borderWidth: 1, borderColor: colours.line },
  name: { fontSize: 18, fontWeight: '600', color: colours.ink },
  meta: { fontSize: 15, color: colours.text },
})
TSX

The Profile tab is a placeholder for now. It holds a real sentence rather than an empty screen, so a tester knows it is unfinished on purpose:

Bash
cat > "src/app/(tabs)/profile.tsx" <<'TSX'
import { StyleSheet, Text, View } from 'react-native'

import { colours } from '@/theme'

export default function ProfileScreen() {
  return (
    <View style={styles.screen}>
      <Text style={styles.title}>Your profile</Text>
      <Text style={styles.body}>Your name and mobile number appear here after your first booking.</Text>
    </View>
  )
}

const styles = StyleSheet.create({
  screen: { flex: 1, padding: 16, gap: 8, backgroundColor: colours.canvas },
  title: { fontSize: 20, fontWeight: '600', color: colours.ink },
  body: { fontSize: 16, color: colours.text },
})
TSX

Now the detail screen, src/app/appointments/[id].tsx. Like the time screen, it types its parameter from the route and handles an ID it does not know:

Bash
cat > "src/app/appointments/[id].tsx" <<'TSX'
import { Link, Stack, useLocalSearchParams } from 'expo-router'
import { StyleSheet, Text, View } from 'react-native'

import { findAppointment, formatWhen } from '@/data/appointments'
import { colours } from '@/theme'

export default function AppointmentScreen() {
  const { id } = useLocalSearchParams<'/appointments/[id]'>()
  const appointment = findAppointment(id)

  if (!appointment) {
    return (
      <View style={styles.screen}>
        <Stack.Screen options={{ title: 'Not found' }} />
        <Text style={styles.title}>There is no appointment {id}.</Text>
        <Link href="/appointments" style={styles.link}>
          See your appointments
        </Link>
      </View>
    )
  }

  return (
    <View style={styles.screen}>
      <Stack.Screen options={{ title: appointment.service }} />
      <Text style={styles.title}>{appointment.service}</Text>
      <Text style={styles.body}>{appointment.practitioner}</Text>
      <Text style={styles.body}>{formatWhen(appointment.startsAt)}</Text>
      <Text style={styles.note}>Please arrive 10 minutes early and bring any medicines you take.</Text>
    </View>
  )
}

const styles = StyleSheet.create({
  screen: { flex: 1, padding: 16, gap: 8, backgroundColor: colours.canvas },
  title: { fontSize: 22, fontWeight: '700', color: colours.ink },
  body: { fontSize: 17, color: colours.text },
  note: { fontSize: 15, color: colours.muted, marginTop: 8 },
  link: { fontSize: 16, color: colours.accent, paddingVertical: 12 },
})
TSX

The tab file (tabs)/appointments.tsx and the folder appointments/ share a name without clashing: the first owns /appointments exactly, and the second owns anything one level below it, such as /appointments/42.

Three phone screens side by side: the Book tab with the service list and tab bar, the time screen inside the Book stack with the tab bar still showing, and the appointment detail screen covering the tab bar with a back button
Screens in the Book stack keep the tab bar. The appointment detail lives in the root stack, so it covers it.

Check it worked

Bash
find src/app -name "*.tsx" | wc -l | tr -d ' '

It prints 10, one file for each row of the route table.

Step 7 · Run the app on a phone and in a browser

Start the development server and open the app in Expo Go, a simulator or the browser, as in the first Expo tutorial:

Bash
cd ~/larkfield-app-demo
npx expo start

Walk through it: the app opens on the Book tab, tapping General check-up shows the time screen with the tab bar still at the bottom, the header's back button returns to the services, and the Appointments tab opens a detail screen that covers the tab bar. Switch to Profile and back to Book while on the time screen: Book remembers where you were, because each tab keeps its own stack. Starting the development server also writes the route types into expo-env.d.ts and .expo/types, which is when your editor starts checking the href patterns.

To check the screens without a device, build the web version of the app. The export bundles every route, so a broken import in any screen stops it with the file name:

Bash
cd ~/larkfield-app-demo
npx expo export --platform web

The output lists the bundles and ends with Exported: dist. The template sets web.output to server in app.json, so dist has a client and a server folder. Serve the export the way it would run in production:

Bash
npx expo serve

Open the address it serves on, http://localhost:8081 by default, in a browser. Stop the server with Ctrl+C when you are done.

Check it worked

The browser lands on /book with the service list and a tab bar with Book, Appointments and Profile. Choosing General check-up lists Dr Chidi Okafor and Ama Mensah but not the nurse, who does not offer check-ups, and tapping a time shows "You chose ...". /appointments/42 shows the check-up, /appointments/999 says there is no such appointment, and /no-such-page shows the not-found screen. Typing addresses into the browser is a quick way to try deep links before part 6 sets them up on phones.

Step 8 · Add a first test of the route tree

Each later part adds tests, so set Jest up now, while the app is small. jest-expo is Expo's Jest preset: it mocks the native side of Expo's modules and compiles TypeScript and JSX the same way the app does. React Native Testing Library renders components and finds them the way a person would, by text, label and role. On SDK 58 it needs version 14 and its renderer, test-renderer; the old react-test-renderer does not support React 19:

Bash
cd ~/larkfield-app-demo
npx expo install jest-expo jest @types/jest -- --save-dev
npm install --save-dev @testing-library/react-native@14.1.0 test-renderer@1.3.1
npm pkg set jest.preset=jest-expo scripts.test=jest

npx expo install picks the jest-expo version that matches SDK 58 and passes everything after -- on to npm. npm pkg set adds the jest section and a test script to package.json without opening it.

Expo Router ships its own test helper, renderRouter, which builds a navigator tree from a folder of route files and opens it at an address, without a device. Point it at your real src/app, so the test covers the layouts you wrote and not a copy. Tests must not go inside src/app, because every file there becomes a route; that is why you made src/__tests__:

Bash
cat > src/__tests__/routes.test.tsx <<'TSX'
import { renderRouter, screen } from 'expo-router/testing-library'

test('the app opens on the Book tab with all three tabs', async () => {
  await renderRouter('./src/app', { initialUrl: '/' })

  expect(screen).toHavePathname('/book')
  expect(screen.getByText('What do you need?')).toBeOnTheScreen()
  expect(screen.getByText('General check-up')).toBeOnTheScreen()
  for (const tab of ['Book', 'Appointments', 'Profile']) {
    expect(screen.getByRole('button', { name: new RegExp(`^${tab}, tab`) })).toBeOnTheScreen()
  }
})

test('the time screen lists only the practitioners for that service', async () => {
  await renderRouter('./src/app', { initialUrl: '/book/vaccination' })

  expect(screen.getByText('Nurse Grace Wanjiru')).toBeOnTheScreen()
  expect(screen.getByText('Dr Chidi Okafor')).toBeOnTheScreen()
  expect(screen.queryByText('Ama Mensah')).toBeNull()
})

test('an appointment link opens the detail screen', async () => {
  await renderRouter('./src/app', { initialUrl: '/appointments/42' })

  expect(screen).toHavePathname('/appointments/42')
  expect(screen.getByText('Dr Chidi Okafor')).toBeOnTheScreen()
  expect(screen.getByText(/arrive 10 minutes early/)).toBeOnTheScreen()
})
TSX
npx jest

toHavePathname is a matcher that expo-router/testing-library adds to Jest. It checks the address the router ended up on, which is how the first test proves that / redirects to /book. The tab query uses what VoiceOver announces on iOS (jest-expo renders as iOS by default): each tab is a button labelled like Book, tab, 1 of 3. On Android the bottom tab bar gives each tab the tab role instead and adds no such label, so a test that renders as Android would query by role tab and the tab title.

Check it worked

Jest reports Tests: 3 passed, 3 total. To see the test catch a real mistake, open src/app/(tabs)/_layout.tsx, change title: 'Profile' to title: 'Account', and run npx jest again: the first test fails because it cannot find a tab called Profile. Put the title back and run it once more.

Step 9 · Check the project's health

expo-doctor checks the project against SDK 58: package versions that do not match, duplicate native modules, and configuration problems. Run it now, and again whenever you add a library:

Bash
cd ~/larkfield-app-demo
npx expo-doctor

Check it worked

The last line says that all checks passed, something like 20/20 checks passed. No issues detected! (the number of checks changes between versions). If a check fails, it names the package and the command that fixes it, usually npx expo install --check. Keep ~/larkfield-app-demo for the next part.

Next steps

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.