title: TypeError: scrollIntoView is not a function
body: <p>I am new to react-testing-library / jest and attempting to write a test to see if the navigation of routes (using react-router-dom) is performed correctly.  So far I have been following the <a href="https://github.com/kentcdodds/react-testing-library" rel="noreferrer">README</a> and this <a href="https://github.com/kentcdodds/react-testing-library/blob/master/examples/__tests__/react-router.js" rel="noreferrer">tutorial</a> on how to use.</p>
  
  <p>One of my components uses scrollIntoView in a local function and this causes the test to fail.  </p>
  
  <pre><code>TypeError: this.messagesEnd.scrollIntoView is not a function
  
    45 |
    46 |     scrollToBottom = () =&gt; {
  &gt; 47 |         this.messagesEnd.scrollIntoView({ behavior: "smooth" });
       |                          ^
    48 |     }
    49 |
    50 | 
  </code></pre>
  
  <p>This is the function in my chatbot component:</p>
  
  <pre><code>componentDidUpdate() {
      this.scrollToBottom();
  }
  
  scrollToBottom = () =&gt; {
      this.messagesEnd.scrollIntoView({ behavior: "smooth" });
  }
  </code></pre>
  
  <p>And this is a sample of the tests that fail:</p>
  
  <pre><code>test('&lt;App&gt; default screen', () =&gt; {
  
      const { getByTestId, getByText } = renderWithRouter(&lt;App /&gt;)
  
      expect(getByTestId('index'))
  
      const leftClick = {button: 0}
      fireEvent.click(getByText('View Chatbot'), leftClick) &lt;-- test fails
  
      expect(getByTestId('chatbot'))
  
  })
  </code></pre>
  
  <p>I have tried to use a mock function, however the error still remains.</p>
  
  <p>This is where this.messageEnd is assigned:</p>
  
  <pre><code>    &lt;div className="chatbot"&gt;
          &lt;div className="chatbot-messages"&gt;
              //render messages here
          &lt;/div&gt;
          &lt;div className="chatbot-actions" ref={(el) =&gt; { this.messagesEnd = el; }}&gt;
              //inputs for message actions here
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>I referenced code from this stack overflow question: <a href="https://stackoverflow.com/questions/37620694/how-to-scroll-to-bottom-in-react">How to scroll to bottom in react?</a></p>
  
  <p><strong>SOLUTION</strong></p>
  
  <pre><code>test('&lt;App&gt; default screen', () =&gt; {
  
      window.HTMLElement.prototype.scrollIntoView = function() {};
  
      const { getByTestId, getByText } = renderWithRouter(&lt;App /&gt;)
  
      expect(getByTestId('index'))
  
      const leftClick = {button: 0}
      fireEvent.click(getByText('View Chatbot'), leftClick)
  
      expect(getByTestId('chatbot'))
  
  })
  </code></pre>