Testing
Testing React Native apps for Meta Horizon OS follows the same principles as testing any React Native application. This guide covers recommended tools and practices for writing maintainable, reliable tests.
Philosophy
The goal of testing is to give you confidence that your app works correctly. The best way to achieve this is to test how users interact with your app, not implementation details.
As Kent C. Dodds puts it: "The more your tests resemble the way your software is used, the more confidence they can give you."
What to Test
Focus on use cases, not code coverage:
- User interactions: Button presses, text input, gestures
- Rendered output: What the user sees on screen
- Prop changes: How components respond to different inputs
- Edge cases: Error states, loading states, empty states
What Not to Test
Avoid testing implementation details:
- Internal component state
- Private methods
- Component lifecycle methods
- Specific implementation approaches
Testing implementation details leads to:
- False negatives: Tests break during refactoring even when functionality works
- False positives: Tests pass even when bugs exist
Recommended Tools
React Native Testing Library
React Native Testing Library is the recommended testing library. It encourages testing from the user's perspective.
Query Priority
When querying elements, prefer queries that reflect how users find elements:
Query Variants
Choose the right variant for your situation:
getBy*- Element exists, returns immediatelyqueryBy*- Element may not exist (returns null)findBy*- Element appears asynchronously (returns promise)*AllBy*- Multiple elements expected
MSW for API Mocking
Mock Service Worker (MSW) intercepts network requests at the network level, providing realistic API mocking without modifying your application code.
Example Test
Here's a complete example testing a login form:
Test Prioritization
For large applications, prioritize tests by user impact:
- Identify critical paths: What would upset users most if broken?
- Start with integration tests: Cover the happy path of important features
- Add edge case tests: Error handling, boundary conditions
- Unit test complex logic: Business rules, calculations, data transformations
Don't aim for 100% code coverage. Focus on meaningful coverage of user-facing functionality.
End-to-End Testing
For full end-to-end testing of your app running on Meta Horizon OS, you can use Maestro — an open-source UI testing framework that supports React Native apps. With the Meta Spatial Simulator, Maestro can automate user flows by interacting with your app just like a real user would: tapping elements, entering text, and validating screen content.
Maestro Studio provides a visual IDE for building tests without writing code, while the CLI integrates seamlessly into CI pipelines. Since the testing workflow is standard across all React Native platforms, refer to the official Maestro documentation for setup and usage instructions.
