I have an action creator, how should i test it with jest ? The problem is , i cant even enter Api function , that is why i cant get LOGIN_SUCCESS, When i check store.getState() it get me only LOGIN_REQUEST and LOGIN_FAILURE
const authUser = (login, password) => async (dispatch) => {
dispatch({
type: actionTypes.LOGIN_REQUEST,
});
try {
return await Api('login', 'post', { login, password })
.then((response) => {
const { data } = response;
if (data.error) {
throw data;
}
const { value } = response.data;
let encoded = [];
encoded = JSON.parse(Base64.decode(value));
dispatch({
type: actionTypes.LOGIN_SUCCESS,
payload: {
encoded,
},
});
return encoded;
})
.catch((error) => {
throw error;
});
} catch (error) {
dispatch({
type: actionTypes.LOGOUT_FAILURE,
payload: {
error,
},
});
}
};
api.js
axios.defaults.withCredentials = true;
const Api = (path, method, data) => {
return axios({
method,
url: `${process.env.REACT_APP_URL}${path}`,
headers: {
Authorization: `Basic ${process.env.REACT_APP_SECRET_TOKEN}`,
'Content-Type': 'application/json;charset=utf-8',
},
data,
});
};