title: How to test a function in jest?
body: <pre class="lang-js prettyprint-override"><code>const updateSession = async (emitter, dbModel, center_id, session_id, data) =&gt; {
  
      if (await dbModel.update('session', {center_id, session_id, data})) {
          const result = {
              center_id: `k${center_id}`,
              session_id: session_id,
              ...data
          } ;
          emitter.emit('updateSession', {
              operationType: 'update',
              operationOn: 'session',
              data: result
          }) ;
      } else throw new Error('500 Internal Server Error') ;
  }
  </code></pre>
  <blockquote>
  <p><code>emitter</code> is an EventEmitter</p>
  <p><code>dbModel</code> is a module to interact with database</p>
  <p><code>center_id</code> is a number</p>
  <p><code>session_id</code> is a string</p>
  <p><strong>All of the above are same in all cases</strong></p>
  </blockquote>
  <p>I need to test this fucntion in jest with 3 different cases where</p>
  <blockquote>
  <p>case 1 : <code>data = {available_capacity1: 4, available_capacity2: 6}</code></p>
  <p>case 2 : <code>data = {available_capacity1: 4}</code></p>
  <p>case 3 : <code>data = {available_capacity2: 6}</code></p>
  </blockquote>
  <p>Conditions :</p>
  <blockquote>
  <p>In case 1 the test should pass if <code>data</code> passed to callback of event
  listener, that is :<code>emitter.on('updateSession', callback)</code>, has both
  <code>available_capacity1</code> and <code>available_capacity2</code> properties in <code>data.result</code>
  object</p>
  <p>In case 2 the test should pass if <code>data</code> passed to callback of event
  listener has only <code>available_capacity1</code> property in <code>data.result</code> object</p>
  <p>In case 3 the test should pass if <code>data</code> passed to callback of event
  listener has only <code>available_capacity2</code> property in <code>data.result</code> object</p>
  </blockquote>
  <p>I would like to know how can I write a test for the above mentioned cases in jest</p>
  <p>any help is much appreciated, Thanks in advance.</p>