Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
How to mock an async redux action in jest?

I'm using jest in my expo project for unit testing. I am new to jest I don't know how to use mock functions to test my redux actions.Following is my action for SignIn.

authActions.ts

..
import Api, {
  SubscriptionPreference,
} from "@myPackage/api";
...
    export const signIn =
      ({ email, phoneNumber, password }) =>
      async (dispatch) => {
        console.log("DATA")
        dispatch({ type: types.STATE_LOADING });
      try {
           const result = (
            await Api.accounts.accountsLogin({
              email,
              phoneNumber,
              password,
            })
          ).data;    
     
          if (!result.success) {
            throw new Error(i18n.t("signin_incorrectUsername"));
          }
    
          await SecureStore.setItemAsync("authtoken", result.token);
          dispatch(loadAuth());
        } catch (e) {
          const errorMessage = e.error?.message || e.message;
          Alert.alert(errorMessage);
          dispatch({
            type: types.AUTH_ERROR,
            payload: errorMessage,
          });
        }
      };

The Api is being called from my custom package.So I am not sure how to write a test suite for my signIn action. I have gone through several documentation but couldn't find a proper one for my case. If anybody knows the answer please help. Any help would be really appreciable. Thank you

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!