title: Jest: toThrow() matcher
body: <p>Context: React application with mobx.</p>
  
  <p>Anyway I've a class (a store), <strong>catalogStore</strong>,  with a <strong>loadProducts</strong> method. This method call a service to get the data and then, return it.</p>
  
  <p>I've to write a test that say "If it cannot get the data, then throw an exception"</p>
  
  <p>I mocked the function supposed to get the data, forcing it to reject... ok</p>
  
  <p>This is the test I wrote</p>
  
  <pre><code>describe("catalogStore", () =&gt; {
    describe("if the catalog fails to get the data", () =&gt; {
      beforeAll(() =&gt; {
        catalogService.get = jest.fn().mockImplementation(() =&gt; {
          return new Promise((resolve, reject) =&gt; {
            reject("rejected error");
          });
        });
      });
  
      it("should throw an error", () =&gt; {
        return expect(() =&gt; catalogStore.loadProducts()).toThrow();
      });
    });
  });
  </code></pre>
  
  <p>And this is the loadProducts function:</p>
  
  <pre><code>loadProducts() {
    return catalogService
      .get()
      .then(result =&gt; {
        this.products = result.services;
        return {products: this.products};
      })
      .catch(error =&gt; {
        console.log("CatalogStore loadProducts error catch: ", error);
        return { error };
      })
      .then(({ error }) =&gt; {
        if (error) {
          console.log("Im gonna throw the error -&gt; ", error);
          throw error;
        }
      });
  }
  </code></pre>
  
  <p>From the logs I can see "Im gonna throw the error -> rejected error", but the test fails with this message:</p>
  
  <blockquote>
    <p>Expected the function to throw an error. But it didn't throw anything.</p>
  </blockquote>
  
  <p>Why? I'm throwing the error.</p>
  
  <p>Luca</p>