title: How do I write test for error throwing in jasmine?
body: <p>I would like to test if error has been thrown.</p>
  
  <p>Here is my example code:</p>
  
  <pre><code>export const lambdaHandler = async (event: any, context: any, callback: any) =&gt; {
  
  switch(param) {
     case 1: /.../
     case 2: /.../
     default: throw new Error('error')
     }
  }
  </code></pre>
  
  <p>Tests which I've tried</p>
  
  <pre><code>await lambdaHandler(event, {}, i.callback);
  
  expect(lambdaHandler).toThrow();
  </code></pre>
  
  <p>and also</p>
  
  <pre><code>const res = await lambdaHandler(event, {}, i.callback);
  
  expect(res).toThrow();
  </code></pre>
  
  <pre><code>const res = await lambdaHandler(event, {}, i.callback);
  
  expect(res).toEqual('error');
  </code></pre>
  
  <p>and</p>
  
  <pre><code>await lambdaHandler(event, {}, i.callback);
  
  expect(async ()=&gt; {
     await lambdaHandler(event, {}, i.callback);
  }).toEqual('error');
  </code></pre>
  
  <pre><code>await lambdaHandler(event, {}, i.callback);
  
  expect(async ()=&gt; {
     await lambdaHandler(event, {}, i.callback);
  }).toThrow();
  </code></pre>
  
  <p>method </p>
  
  <pre><code>.toThrowError()
  </code></pre>
  
  <p>doesn't work for me too.</p>
  
  <p>The result which I generally get is</p>
  
  <pre><code> Message:
      Error: error
  </code></pre>