Skip to content

Instantly share code, notes, and snippets.

@Frank1234
Last active November 23, 2019 13:06
Show Gist options
  • Save Frank1234/ab5eacf58a153b606f9c0ed01257e18a to your computer and use it in GitHub Desktop.
Save Frank1234/ab5eacf58a153b606f9c0ed01257e18a to your computer and use it in GitHub Desktop.
Class that can add testIDs on both Android and iOS debug builds
import {Platform} from 'react-native';
const getPlatformTestId = (id: string) =>
Platform.OS === 'ios' ? {testID: id} : {accessible: true, accessibilityLabel: id};
/**
* Adds a testID to the views on Android and iOS in their specific ways. On Android,
* this will result in a ContentDescription on Debug builds (and no changes on live builds).
*/
const setTestID = (id : string) =>
__DEV__ ? getPlatformTestId(id) : null;
export default setTestID;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment