title: Unhandled promise rejection warning with Mocha, Chai and Sinon
body: <p>I'm using <code>Node</code> and have the following <code>ES6</code> class:</p>
  
  <pre><code>const moment = require('moment');
  
  const sqlFileReader = require('../database/SqlFileReader');
  const Lnfe = require('../errors/LoanNotFoundError');
  
  const epoch = '1970-01-01';
  
  /**
   * Take the input params and return the clientId (either found via loanId or untouched) and dateString we need
  */
  class ParameterParser {
  
  static async prepareInputParameters(con, req) {
  
      let clientId = req.query.client_id; // Will be overriden if we need and are able to obtain the client id via loan id.
      let dateString;
  
      // If no client_id is given but loan_id is, get the client_id via loan_id:
      if (typeof req.query.client_id === 'undefined' &amp;&amp; typeof req.query.loan_id !== 'undefined') {
          const { retData } = await sqlFileReader.read('./src/database/sql/getClientIdFromLoanId.sql', [`${req.query.loan_id}`], con, req.logger);
          if (retData.rowsCount &gt; 0) {
              clientId = retData.rows[0].client_id;
          }
          else {
              throw new Lnfe(400, req);
          }
      }
  
      if (typeof req.query.complaint_init_date === 'undefined') {
          dateString = epoch;
      }
      else {
          // Need to subtract 6 years from the complaint_init_date:
          dateString = moment(moment(req.query.complaint_init_date, 'YYYY-MM-DD').toDate()).subtract(6, 'years').format('YYYY-MM-DD');
      }
  
      return { clientId, dateString };
  }
  
  }
  
  module.exports = ParameterParser;
  </code></pre>
  
  <p>I am testing it using <code>Mocha</code>, <code>Chai</code>, <code>Chai-as-Promised</code> and <code>Sinon</code>:</p>
  
  <pre><code>'use strict';
  
  const chai = require('chai');
  const chaiAsPromised = require('chai-as-promised');
  const sinon = require('sinon');
  
  const parameterParser = require('../../src/core/ParameterParser.js');
  const sqlFileReader = require('../../src/database/SqlFileReader.js');
  const Lnfe = require('../../src/errors/LoanNotFoundError');
  
  chai.use(chaiAsPromised);
  const { expect } = chai;
  
  const retData = {
  rowsCount: 1,
  rows: [{ client_id: 872 }],
  };
  
  const reqDateAndLoan = {
  query: {
      complaint_init_date: '2022-03-15',
      loan_id: '1773266',
  },
  };
  
  const reqDateAndClient = {
  query: {
      complaint_init_date: '2022-03-15',
      client_id: '872',
  },
  };
  
  const reqDateAndLoanIdThatDoesNotExist = {
  query: {
      complaint_init_date: '2022-03-15',
      loan_id: '1773266999999999999',
  },
  };
  
  describe('prepareInputParameters', () =&gt; {
  
  sinon.stub(sqlFileReader, 'read').returns({ retData });
  
  it('results in correct client id and date string', async () =&gt; {
      const ret = { clientId: 872, dateString: '2016-03-15' };
      expect(await parameterParser.prepareInputParameters(null, reqDateAndLoan)).to.deep.equal(ret);
  });
  
  it('results in a client id equal to the that input if the request query contains a client id', async () =&gt; {
      const ret = { clientId: '872', dateString: '2016-03-15' };
      expect(await parameterParser.prepareInputParameters(null, reqDateAndClient)).to.deep.equal(ret);
  });
  
  it('throws a \'Loan Not Found\' error', async () =&gt; {
      expect(parameterParser.prepareInputParameters(null, reqDateAndLoanIdThatDoesNotExist)).eventually.throw(Lnfe, 400, 'Loan Not Found');
  });
  
  it('DOES NOT throw a \'Loan Not Found\' error', async () =&gt; {
      expect(async () =&gt; {
          await parameterParser.prepareInputParameters(null, reqDateAndLoanIdThatDoesNotExist);
      }).to.not.throw(Lnfe, 400, 'Loan Not Found');
  });
  
  
  });
  </code></pre>
  
  <p>The tests pass but the output has an couple of node warnings:</p>
  
  <pre><code>prepareInputParameters
  ✓ results in correct client id and date string
  ✓ results in a client id equal to the that input if the request query contains a client id
  ✓ throws a 'Loan Not Found' error
  (node:23875) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): AssertionError: Loan Not Found: expected { Object (clientId, dateString) } to be a function
  (node:23875) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  ✓ DOES NOT throw a 'Loan Not Found' error
  
  
  4 passing (19ms)
  </code></pre>
  
  <p>Any ideas how I can get rid of these warnings or what I'm doing wrong?  </p>