title: How can I test chained promises in a Jest test?
body: <p>Below I have a test for my <em>login</em> actions. I'm mocking a Firebase function and want to test if the <em>signIn</em>/<em>signOut</em> functions are called.</p>
  <p>The tests pass. However, I do not see my second console log. Which is this line <code>console.log('store ==&gt;', store);</code>.</p>
  <pre><code>it('signIn should call firebase', () =&gt; {
    const user = {
      email: 'first.last@yum.com',
      password: 'abd123'
    };
  
    console.log('111');
    return store.dispatch(signIn(user.email, user.password)).then(() =&gt; {
      console.log('222'); // Does not reach
      expect(mockFirebaseService).toHaveBeenCalled();
    });
    console.log('333');
  });
  </code></pre>
  <blockquote>
  <p>● login actions › signIn should call Firebase</p>
  </blockquote>
  <blockquote>
  <p>TypeError: auth.signInWithEmailAndPassword is not a function</p>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/vlZ0o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vlZ0o.png" alt="Enter image description here" /></a></p>
  <h2>Action being tested</h2>
  <pre><code>// Sign in action
  export const signIn = (email, password, redirectUrl = ROUTEPATH_DEFAULT_PAGE) =&gt; (dispatch) =&gt; {
    dispatch({ type: USER_LOGIN_PENDING });
  
    return firebase
      .then(auth =&gt; auth.signInWithEmailAndPassword(email, password))
      .catch((e) =&gt; {
        console.error('actions/Login/signIn', e);
        // Register a new user
        if (e.code === LOGIN_USER_NOT_FOUND) {
          dispatch(push(ROUTEPATH_FORBIDDEN));
          dispatch(toggleNotification(true, e.message, 'error'));
        } else {
          dispatch(displayError(true, e.message));
          setTimeout(() =&gt; {
            dispatch(displayError(false, ''));
          }, 5000);
          throw e;
        }
      })
      .then(res =&gt; res.getIdToken())
      .then((idToken) =&gt; {
        if (!idToken) {
          dispatch(displayError(true, 'Sorry, there was an issue with getting your token.'));
        }
  
        dispatch(onCheckAuth(email));
        dispatch(push(redirectUrl));
      });
  };
  </code></pre>
  <h2>Full Test</h2>
  <pre><code>    import configureMockStore from 'redux-mock-store';
  import thunk from 'redux-thunk';
  
  // Login Actions
  import {
    // onCheckAuth,
    signIn,
    signOut
  } from 'actions';
  
  import {
    // USER_ON_LOGGED_IN,
    USER_ON_LOGGED_OUT
  } from 'actionTypes';
  
  // String Constants
  // import { LOGIN_USER_NOT_FOUND } from 'copy';
  
  const middlewares = [thunk];
  const mockStore = configureMockStore(middlewares);
  
  // Mock all the exports in the module.
  function mockFirebaseService() {
    return new Promise(resolve =&gt; resolve(true));
  }
  
  // Since &quot;services/firebase&quot; is a dependency on this file that we are testing,
  // we need to mock the child dependency.
  jest.mock('services/firebase', () =&gt; new Promise(resolve =&gt; resolve(true)));
  
  describe('login actions', () =&gt; {
    let store;
  
    beforeEach(() =&gt; {
      store = mockStore({});
    });
  
    it('signIn should call firebase', () =&gt; {
      const user = {
        email: 'first.last@yum.com',
        password: 'abd123'
      };
  
      console.log('111');
      return store.dispatch(signIn(user.email, user.password)).then(() =&gt; {
        console.log('222'); // does not reach
        expect(mockFirebaseService).toHaveBeenCalled();
      });
      console.log('333');
    });
  
    it('signOut should call firebase', () =&gt; {
      console.log('signOut should call firebasew');
      store.dispatch(signOut()).then(() =&gt; {
        expect(mockFirebaseService).toHaveBeenCalled();
        console.log('store ==&gt;', store);
        expect(store.getActions()).toEqual({
          type: USER_ON_LOGGED_OUT
        });
      });
      console.log('END');
    });
  });
  </code></pre>