title: Mock of promise based method is not working
body: <p>Trying to write a tests in <strong>JEST</strong> for my node.js written in typescript. The function which I want to test is very complex (I mean a lot of stuff are happening inside). It returns a <strong>Promise</strong> and inside it there are 2 other functions which are returning a <strong>Promises</strong> (one of it it's making async call) + the are <strong>BehaviorSubject</strong>, <strong>Observables</strong>  (created with <strong>forEach</strong> from an array) with <strong>forkJoin</strong> .</p>
  
  <p>I'm trying to mock the response of 1 of the nested <strong>Promise</strong> based function. The result of it is assign to an <strong>Observable</strong>. The reason why I'm trying to change the response of it is because I want to test my master function.</p>
  
  <p>The problems which I'm facing are that when I'm creating the mock of the async function the test on the master function looks like it's ignoring my mock and going to the original one.</p>
  
  <p>Here is an example (try to simplify it) of my module:</p>
  
  <pre><code>import { BehaviorSubject, forkJoin } from 'rxjs'
  
  export const tableConfig: any[] = [{
      tableName: 'TableOne'
  },
  {
      tableName: 'TableTwo'
  },
  {
      tableName: 'TableThree'
  }];
  
  const exampleApiTableData: any = {
      TableOne: [],
      TableTwo: [],
      TableThree: [],
  }
  
  export const pullTableData = (tableName: string): Promise&lt;any[]&gt; =&gt; { //async Promise function 1
      return new Promise((resolve, reject) =&gt; {
          // Here is a async api call with some more logic but to make it simple and short giving such an example
          setTimeout(() =&gt; {
              resolve(exampleApiTableData[tableName]);
          }, 1000);
      })
  }
  
  export const buildNewTable = (tableOne: any[], tableTwo: any []): Promise&lt;any[]&gt; =&gt; { // Promise function 2
      return new Promise((resolve, reject) =&gt; {
          //simplified example
          resolve(tableOne.concat(tableTwo));
      })
  }
  
  export const getTables = (): Promise&lt;any&gt; =&gt; { // Master
      return new Promise((resolve, reject) =&gt; {
          const errors: string[] = [];
          const allTableData$: any[] = [];
          const observableNames: any = {};
  
          tableConfig.forEach(table =&gt; {
              observableNames[table.tableName + 'Source'] = new BehaviorSubject&lt;string[]&gt;([]);
              observableNames[table.tableName] = observableNames[table.tableName + 'Source'].asObservable();
              allTableData$.push(observableNames[table.tableName]);
              pullTableData(table.tableName).then((result: any[]) =&gt; {
                  observableNames[table.tableName + 'Source'].next(result);
                  observableNames[table.tableName + 'Source'].complete();
              }).catch((error: any) =&gt; {
                  errors.push(error);
                  observableNames[table.tableName + 'Source'].next(error);
                  observableNames[table.tableName + 'Source'].complete();
              })
          });
  
          forkJoin(allTableData$).subscribe((results: any) =&gt; {
              if (errors.length &gt; 0) reject(errors);
              buildNewTable(observableNames.TableOneSource.value, observableNames.TableTableTwoSource.value).then((result: any[]) =&gt; {
                  // console.log(result);
                  resolve(result);
              }).catch((error: any) =&gt; {
                  // console.log(error);
                  reject(error);
              });
          });
      });
  }
  </code></pre>
  
  <p>This is the test I created but instead of getting the <strong>mockRejectedValue</strong> value it's calling <strong>pullTableData</strong> all the time</p>
  
  <pre><code>import * as tableMethods from './index'
  
  describe(`Test the Table methods`, () =&gt; {
      test(`it should return and error`, () =&gt; {
          const expectedError = `I'm an error`
          jest.fn(tableMethods.pullTableData).mockRejectedValue(expectedError);
  
          return tableMethods.getTables().then((data: any) =&gt; {
  
          }).catch((error: any) =&gt; {
              expect(error).toBe(expectedError);
          })
      })
  })
  </code></pre>
  
  <p>What I'm doing wrong?
  Is there a way to mock the <strong>pullTableData</strong> and the <strong>buildNewTable</strong> so I can test the <strong>getTable</strong> function?</p>