title: Jest pass in catch and finally block, but doesn't assert the expects inside them
body: <p>I'm testing a typescript function where is done a typeorm transaction:</p>
  <p>budgetSave.ts</p>
  <pre><code>export async function save(budget: Budget, connection: Connection) : Promise&lt;Budget&gt; {
      const queryRunner = connection.createQueryRunner();
      await queryRunner.startTransaction();
      try {
          await queryRunner.manager.softDelete(Budget, {code: budget.code });
          budget = await queryRunner.manager.save(budget);
          await queryRunner.commitTransaction();
      } catch (e) {
          console.error(`Error: + ${e.message}`);
          await queryRunner.rollbackTransaction();
          throw e;
      } finally {
          await queryRunner.release();
      }
      return budget;
  }
  </code></pre>
  <p>budgetSave.spec.ts</p>
  <pre><code>import { Connection, EntityManager, QueryRunner } from &quot;typeorm&quot;;
  import { save, handle } from &quot;services/budgetSave&quot;;
  import { Budget } from &quot;libs/entities/budget&quot;;
  
  describe('test should handle price', () =&gt; {
      it('should rollback when throws an error', async () =&gt; {
        console.error = jest.fn();
  
        const budget = {
          id: 1,
          code: 'B-123',
          email: 'test@example.com',
          value: 990.90,
          active: true,
          created: Date.now
        } as Budget;
        const errorMessage = 'Error to write in database';
    
        const entityManager: EntityManager = {
          softDelete: jest.fn().mockRejectedValueOnce(new Error(errorMessage))
        } as unknown as EntityManager;
    
        const queryRunner: QueryRunner = {
          startTransaction: jest.fn().mockImplementationOnce(async() =&gt; Promise.resolve()),
          rollbackTransaction: jest.fn().mockImplementationOnce(async() =&gt; Promise.resolve()),
          release: jest.fn().mockImplementationOnce(async() =&gt; Promise.resolve()),
          manager: entityManager
        } as unknown as QueryRunner;
    
        const mockedConnection = {
          createQueryRunner: jest.fn().mockImplementation(() =&gt; queryRunner)
        } as unknown as Connection;
    
        expect(async () =&gt; {
          await save(budget, mockedConnection);
        }).rejects.toThrow(errorMessage);
  
        expect(console.error).toBeCalledWith('Error: Error to write in database');
        expect(queryRunner.rollbackTransaction).toBeCalled();
        expect(queryRunner.release).toBeCalled();
    
      });
    });
  </code></pre>
  <p>When I'm testing the error case, and I try assert using expect to be called methods and derivations inside the catch and finally blocks, I found the following error:</p>
  <pre><code>● test should handle price › should rollback when throws an error
  
      expect(jest.fn()).toBeCalledWith(...expected)
  
      Expected: &quot;Error: Error to write in database&quot;
  
      Number of calls: 0
  
        41 |       }).rejects.toThrow(errorMessage);
        42 |
      &gt; 43 |       expect(console.error).toBeCalledWith('Error: Error to write in database');
           |                             ^
        44 |       expect(queryRunner.rollbackTransaction).toBeCalled();
        45 |       expect(queryRunner.release).toBeCalled();
        46 |   
  
        at Object.&lt;anonymous&gt; (tests/services/budgetSave..spec.ts:43:29)
  </code></pre>
  <p>To run the tests I used the following line:</p>
  <pre><code>$ yarn jest --coverage
  </code></pre>
  <p>When I comment that line (43), I have an error that the next line won't called. The same happens with the expect at line 45. If I comment all these expectations the test pass and enter in these blocks as it's possible to see in this capture:
  <a href="https://i.stack.imgur.com/KZ5B7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KZ5B7.png" alt="Coverage test pass by catch and finally block" /></a></p>
  <p>I'm wondering what's wrong in these expectations that won't called even the coverage report indicating that pass by there.</p>