title: Checking text appears inside an element using react testing library
body: <p>I'm writing some tests for a React app using <a href="https://testing-library.com/" rel="noreferrer">Testing Library</a>. I want to check that some text appears, but I need to check it appears in a particular place because I know it already appears somewhere else.</p>
  <p>The <a href="https://testing-library.com/docs/dom-testing-library/api-queries#bytext" rel="noreferrer">Testing Library documentation for queries</a> says that the <code>getByText</code> query takes a <code>container</code> parameter, which I guessed lets you search within that container. I tried doing this, with the <code>container</code> and <code>text</code> parameters in the order specified in the docs:</p>
  <pre><code>const container = getByTestId('my-test-id');
  expect(getByText(container, 'some text')).toBeTruthy();
  </code></pre>
  <p>and I get an error: <code>matcher.test is not a function</code>.</p>
  <p>If I put the params the other way round:</p>
  <pre><code>const container = getByTestId('my-test-id');
  expect(getByText('some text', container)).toBeTruthy();
  </code></pre>
  <p>I get a different error: <code>Found multiple elements with the text: some text</code></p>
  <p>Which means it's not searching inside the specified container.</p>
  <p>I think I'm not understanding how <code>getByText</code> works. What am I doing wrong?</p>