How to test Promise catch with Mocha
<p>I'm trying to test the GET HTTP method from a requests module:</p>

<pre><code>const get = (host, resource, options) =&gt; {
  ...
  return new Promise((resolve, reject) =&gt; fetch(url, opts)
    .then(response =&gt; {
      if (response.status &gt;= 400) {
        reject({ 
        message: `[API request error] response status: ${response.status}`, 
        status: response.status });
      }
      resolve(response.json());
    })
    .catch(error =&gt; reject(error)));
};
</code></pre>

<p>And here is how I tested the <code>.then</code> part:</p>

<pre><code>it('Wrong request should return a 400 error ', (done) =&gt; {
    let options = { &lt;parameter&gt;: &lt;wrong value&gt; };
    let errorJsonResponse = {
    message: '[API request error] response status: 400',
    status: 400,
};
let result = {};

result = get(params.hosts.api, endPoints.PRODUCTS, options);

result
  .then(function (data) {
      should.fail();
      done();
    },

    function (error) {
      expect(error).to.not.be.null;
      expect(error).to.not.be.undefined;
      expect(error).to.be.json;
      expect(error).to.be.jsonSchema(errorJsonResponse);
      done();
    }
  );
});
</code></pre>

<p>However I didn't find a way to test the catch part (when it gives an error and the response status is not >= 400).</p>

<p>Any suggestions?</p>

<p>It would also help me solve the problem a simple example with another code  that tests the catch part of a Promise.</p>