Skip to main content
Expo Router provides testing utilities specifically designed for testing file-based routing and navigation in your app.

Setup

Install Dependencies

Configure Jest

jest.config.js

Setup File

Expo Router’s testing utilities include automatic mocks:
jest-setup.js

renderRouter Utility

The renderRouter function renders your routes for testing.

Basic Usage

app/__tests__/routing.test.tsx

With Initial URL

With Layouts

Using router Object

Testing Dynamic Routes

Route Parameters

Query Parameters

Catch-all Routes

Testing Hooks

usePathname

useSegments

useRouter

Testing Layouts

Stack Navigator

Tabs Navigator

Nested Layouts

Testing Redirects

Testing 404/Not Found

Screen Utilities

Pathname Matchers

Screen Methods

Advanced Testing

Testing with Context

Troubleshooting

Timing Issues

Wrap navigation in act():

Async Navigation

Wait for navigation to complete:

Mock File System

For more complex scenarios, use the file system structure:

Best Practices

1. Test User Flows

2. Test Navigation State

3. Test Edge Cases

Next Steps

Unit Testing

Test components and logic

E2E Testing

Test complete user flows

Expo Router

Learn more about Expo Router

Debugging

Debug navigation issues