title: unit test custom hook with jest and react testing library
body: <p>I am trying to unit test a custom hook using jest and react testing library in scenario where error is thrown but I am not able to catch the actual error message, here is my code so far:</p>
  <p>my first hook:</p>
  <pre><code>import react from 'react';
  
  const useFirstHook = () =&gt; {
  
      //I will add conditional logic later
      throw new Error('my custom error is thrown')
  
      const test1 = 'I am test 1';
  
      return {
          test1
      };
  
  };
  
  export default useFirstHook;
  </code></pre>
  <p>test.js</p>
  <pre><code>import React from 'react';
  import { render } from '@testing-library/react';
  
  import useFirstHook from './useFirstHook';
  
  describe('useFirstHook', () =&gt; {
  
      //I also tried adding jest.spy but no luck
      /* beforeAll(() =&gt; {
          jest.spyOn(console, 'error').mockImplementation(() =&gt; {})
      }); */
  
      it('test 1', () =&gt; {
  
          let result;
  
          const TestComponent = () =&gt; {
              result = useFirstHook()
              return null;
          };
  
          render(&lt;TestComponent /&gt;)
  
          //expect()
  
      });
  
  });
  </code></pre>
  <p>my logic is to first create a hook, unit test it and then create component, add hook there and test that component with hook integration as well. what am I missing, or my approach is completely wrong ?</p>