title: How to fix TypeError is not a function (testing promises with Jest)
body: <p>I have a passing test now thanks to the answer here: <a href="https://stackoverflow.com/questions/48468299/how-to-test-is-chained-promises-in-a-jest-test">How to test is chained promises in a jest test?</a></p>
  
  <p>However I'm still getting an error in the catch part of my test.</p>
  
  <p>I seem to not be able to correctly mock or spy this part in the actions file: <code>.then(res =&gt; res.getIdToken())</code></p>
  
  <blockquote>
    <p>TEST signIn ERROR => TypeError: res.getIdToken is not a function</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/DQeMU.png" rel="noreferrer"><img src="https://i.stack.imgur.com/DQeMU.png" alt="enter image description here"></a></p>
  
  <h2>The Test</h2>
  
  <pre><code>jest.mock('services/firebase', () =&gt; new Promise(resolve =&gt; resolve({
    signInWithEmailAndPassword: () =&gt; Promise.resolve({ getIdToken: 'abc123' }),
    getIdToken: () =&gt; jest.fn(),
    signOut: () =&gt; jest.fn()
  })));
  
  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'
      };
  
      return store.dispatch(signIn(user.email, user.password))
        .then(() =&gt; {
          console.log('TEST signIn SUCCESS');
          expect(mockSignIn).toHaveBeenCalled();
          expect(store.getActions()).toEqual({
            type: USER_ON_LOGGED_IN
          });
        })
        .catch((err) =&gt; {
          console.log('TEST signIn ERROR =&gt;', err);
        });
    });
  </code></pre>
  
  <h2>The SignIn actions/Login</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; {
        console.log('auth =&gt;', auth);
        return 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;
        }
      })
  
      // I can't seem to mock this correctly
      .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>