title: testing the catch block using jest
body: <p>how can i test the catch block in the below snippet of code where i am using class </p>
  
  <p>// Sample.js</p>
  
  <pre><code>class Sample{
   constructor(data){
    this.resolvedData = this.retrieveData(data) 
   }
  
   retrieveData(data){
     try{
       const resolvedData = data.map(o =&gt; o.name);
    }catch(error){
      throw error
    }
   }
  
  }
  </code></pre>
  
  <p>// Sample.test.js</p>
  
  <pre><code>const Sample = require('./Sample');
  
  
  describe('Sample File test cases', () =&gt; {
      test('should return the resolvedData', () =&gt; {
          const resolvedSample = [{name: "John", id: 123}, {name: "Doe", id: 3432}]
          const model = new Sample(resolvedSample);
          const expectedResolvedSample = [{name: "John"}, {name: "Doe"}]
          expect(model).toEqual(expectedResolvedSample)
      })
      test('should throw an error', () =&gt; {
          const resolvedSample = {}
          const model = new Sample(resolvedSample) // failing here map method since i am passing an object
          expect(model).toThrow(TypeError);
      })
  })
  </code></pre>
  
  <p>I should fail then only it will come to the catch block and give me full coverage. What am i doing wrong here.</p>
  
  <p>Any help appreciated. </p>