title: getByTestId Not Finding TestID
body: <p>As I mentioned in some of my prior posts, I am new to testing React Native apps. I am trying to test this function that checks if a person is over 21 years old. I am experiment with the React Native testing to see where I should test components, so currently I put them on two elements arbitrarily. However, when I go to get the element by testID, it says that that the testID cannot be found. Below is where I have them currently/initially -- I moved them around to other locations and was yielding the same response. The test scripts are below:</p>
  <pre><code>import '../../../matchMedia.mock';
  import React from 'react';
  import renderer, { act } from 'react-test-renderer';
  import VerificationScreen from '../VerificationScreen';
  import { RecoilRoot } from 'recoil';
  import { render, fireEvent, screen } from '@testing-library/react-native'
  import ReactDOM from 'react-dom';
  
  const mockNavigation = {
    navigate: jest.fn(),
    addListener: jest.fn()
  }
  test('renders correctly', () =&gt; {
    const tree = renderer.create(&lt;RecoilRoot&gt;&lt;VerificationScreen navigation= {mockNavigation}/&gt;&lt;/RecoilRoot&gt;).toJSON();
    expect(tree).toMatchSnapshot();
  });
  
  test('renders default elements', () =&gt; {
    const { getAllByText } = render(&lt;RecoilRoot&gt;&lt;VerificationScreen navigation= {mockNavigation}/&gt;&lt;/RecoilRoot&gt;);
    expect(getAllByText('Can I see some ID?').length).toBe(1);
    expect(getAllByText('You must be of legal drinking age to use this app.').length).toBe(1);
    expect(getAllByText('Enter Now').length).toBe(1);
  
  });
  
  test('display error if the user is not 21', () =&gt; {
    const { getAllByText } = render(&lt;RecoilRoot&gt;&lt;VerificationScreen navigation= {mockNavigation}/&gt;&lt;/RecoilRoot&gt;);
    console.log(getAllByText('MMDDYYYY'));
    fireEvent.changeText(queryByTestId('Verification.DOB'), '10012021');
    fireEvent.press(getByTestId('Verification.Submit'));
  })
  </code></pre>
  <p>The component itself is below:</p>
  <pre><code>import React from 'react';
  import moment from 'moment';
  import { View, Text, StyleSheet, TouchableOpacity, TextInput } from 'react-native';
  import { COLORS } from '../../styles/COLORS';
  import { SHADOWS } from '../../styles/shadows';
  import ClickableText from '../widgets/ClickableText';
  import Logo from '../widgets/Logo';
  import SlideInContainer from '../widgets/SlideInContainer';
  import Spacing from '../widgets/Spacing';
  import ErrorToast from '../widgets/ErrorToast';
  import { handleError } from '../utils/ErrorFunctions';
  import useDateOfBirth from './useDateOfBirth';
  import setStatusBarColor from '../utils/StatusBarColorFunctions';
  
  
  const VerificationScreen = ({ navigation }) =&gt; {
    const [error, setError] = React.useState(null);
    const [dateOfBirth, setDateOfBirth] = useDateOfBirth();
    const [text, setText] = React.useState(dateOfBirth);
    const [inputFocused, setInputFocused] = React.useState(false);
    const [setColor] = setStatusBarColor();
  
    const DATE_LENGTH = 8;
    const ref = React.useRef(null);
  
    const handleOnPress = () =&gt; {
      setInputFocused(true);
      ref.current.focus();
    };
  
    const handleOnBlur = () =&gt; {
      setInputFocused(false);
    };
  
    const onSubmit = () =&gt; {
      // add validation
      if (text.length === DATE_LENGTH) {
        const MM = text.substring(0, 2);
        const DD = text.substring(2, 4);
        const YYYY = text.substring(4);
        const years = moment(new Date())
          .diff(`${YYYY}-${MM}-${DD}`,
            'years', false);
        if (years &gt;= 21) {
          setDateOfBirth(text);
          navigation.navigate('Home');
        } else {
          handleError('Error: You must be 21 to use this app', setError);
        }
      } else {
        handleError('Error: Please input a valid date', setError);
      }
    };
  
    React.useEffect(() =&gt; {
      if (dateOfBirth !== '') {
        setText(dateOfBirth);
      }
    }, [dateOfBirth]);
    
    React.useEffect(() =&gt; {
      setColor(COLORS.red);
    },[])
  
    return (
      &lt;View style={styles.container}&gt;
        &lt;View style={styles.alignment}&gt;
          &lt;TextInput
            ref={ref}
            value={text}
            onChangeText={setText}
            onBlur={handleOnBlur}
            keyboardType=&quot;number-pad&quot;
            returnKeyType=&quot;done&quot;
            textContentType=&quot;oneTimeCode&quot;
            maxLength={DATE_LENGTH}
            style={styles.hidden} /&gt;
          &lt;SlideInContainer&gt;
            &lt;ErrorToast
              error={error} /&gt;
            &lt;Logo /&gt;
            &lt;Text style={styles.title}&gt;Can I see some ID?&lt;/Text&gt;
            &lt;Text style={styles.subtitle}&gt;You must be of legal drinking age to use this app.&lt;/Text&gt;
            &lt;TouchableOpacity
              style={styles.dateInputContainer}
              onPress={() =&gt; handleOnPress()}
              activeOpacity={1}&gt;
              &lt;Text
              style={styles.dateText}
              testID='Verification.DOB'&gt;
                {'MMDDYYYY'.split('').map((val, i) =&gt; {
                  let ret = '';
                  if (i &lt; text.length) {
                    ret = text.charAt(i);
                  } else {
                    ret = val;
                  }
                  if (i === 1 || i === 3) {
                    ret += '/';
                  }
                  return ret;
                })}
              &lt;/Text&gt;
            &lt;/TouchableOpacity&gt;
            &lt;TouchableOpacity
              testID='Verification.Submit'
              onPress={() =&gt; onSubmit()}
              style={styles.buttonContainer}&gt;
              &lt;Text style={styles.buttonText}&gt;
                Enter Now
              &lt;/Text&gt;
            &lt;/TouchableOpacity&gt;
            &lt;Spacing vertical={10} /&gt;
            &lt;Text style={styles.legalText}&gt;By entering this app you are agreeing to our &lt;ClickableText text=&quot;Terms of Service&quot; url=&quot;https://www.google.com&quot; /&gt; and &lt;ClickableText text=&quot;Privacy Policy&quot; url=&quot;https://www.google.com&quot; /&gt; &lt;/Text&gt;
          &lt;/SlideInContainer&gt;
        &lt;/View&gt;
        &lt;Text style={styles.disclaimerText}&gt;
          You must be at least 21 years of age to drink alcoholic beverages. Do not drink and drive, drink to excess or drink with certain medications or medical conditions. For more information, please visit &lt;ClickableText text=&quot;this website&quot; url=&quot;http://www.cdc.gov/alcohol/index.htm&quot;/&gt; or contact your health provider.
          &lt;/Text&gt;
      &lt;/View&gt;
    )
  }
  
  const styles = StyleSheet.create({
    container: {
      flex: 1,
      alignItems: 'center',
      justifyContent: 'center',
      backgroundColor: COLORS.red,
    },
    noteContainer: {
      position: 'absolute',
      bottom: 0,
    },
    alignment: {
      flex: 0.65
    },
    hidden: {
      opacity: 0,
    },
    title: {
      fontFamily: 'open-sans-semi',
      fontSize: 18,
    },
    subtitle: {
      fontFamily: 'open-sans',
      textAlign: 'center',
      paddingHorizontal: 8,
      fontSize: 15,
      paddingTop: 8
    },
    dateInputContainer: {
      padding: 20
    },
    dateText: {
      fontSize: 30,
      fontFamily: 'open-sans',
    },
    buttonContainer: {
      backgroundColor: COLORS.green,
      paddingVertical: 5,
      paddingHorizontal: 35,
      borderRadius: 5,
      ...SHADOWS.button,
    },
    buttonText: {
      color: COLORS.white,
      fontSize: 18,
      fontFamily: 'open-sans-semi',
    },
    legalText: {
      fontFamily: 'open-sans',
      paddingBottom: 20,
      paddingHorizontal: 8,
      fontSize: 12,
      textAlign: 'center'
    },
    disclaimerText: {
      fontFamily: 'open-sans',
      fontSize: 12,
      position: 'absolute',
      bottom: 0, 
      textAlign: 'center',
      justifyContent: 'center'
    }
  })
  
  export default VerificationScreen;
  </code></pre>
  <p>If additional information is needed, please let me know. Thanks in advance!</p>