Testing Android Paths

Testing Android-Only Code Paths

A Platform.OS check keeps both branches in one file; a file pair lets Metro pick one when it bundles, with a storeLink.d.ts giving TypeScript the shared signature:

src/android/storeLink.android.ts and src/android/storeLink.ios.tsShell
// Metro picks this file for Android builds only
export const storeLink = (pkg: string) => `market://details?id=${pkg}`;
// Metro picks this file for iOS builds only
export const storeLink = (appId: string) => `itms-apps://apps.apple.com/app/id${appId}`;

RateApp.tsx imports ./storeLink and branches on Platform.OS between the strings 'ANDROID-BRANCH: ...' and 'IOS-BRANCH: ...'. The iOS side cannot run here, but Metro serves either platform's production bundle on any OS, where Platform.OS is a constant and the dead branch disappears:

Which strings each platform's production bundle containsJSX
for p in android ios; do
  curl -s "http://localhost:8140/index.bundle?platform=$p&dev=false&minify=true" -o $p.js
  found=$(grep -o 'ANDROID-BRANCH\|IOS-BRANCH\|market://\|itms-apps://' $p.js | sort -u)
  echo $p: $found
done
Output
android: ANDROID-BRANCH market://
ios: IOS-BRANCH itms-apps://

Port 8140 is this project's Metro (the default is 8081). On the emulator, adb drives the state that Android-only code depends on, as in every demo of this section:

adb commands that drive Android-only code paths
To test Command
Back button adb shell input keyevent KEYCODE_BACK
Permission from scratch adb shell pm revoke <package> <permission> or pm clear <package>
Dark mode, font size cmd uimode night yes, settings put system font_scale 1.3
Wide window adb shell wm size 2000x2400, then wm size reset

For unit tests, jest-expo ships per-platform presets (jest-expo/android, jest-expo/ios, jest-expo/universal) that resolve the matching file extensions (Testing React Native Apps).