mercredi 30 mai 2018

How do I test this using Jest + Enzyme

I have a react + typescript application and I have an async api call done with axios. I want to test that async call using Jest + Enzyme.

This is what I have for my action

// load items callback
export function loadItemsSuccess(response) {
  return {
    type: LOAD_ITEMS,
    items: response.data
  };
}

// load items 
export function loadItems() {
  return function (dispatch) {
    const authOptions = {
      method: "GET",
      url: "http://192.168.99.100:3000/items
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      json: true
    };
    return axios(authOptions).then(response => {
      dispatch(loadItemsSuccess(response));
    }).catch(error => {
      console.log("Error loading items, error);
    });
  };
}

My reducer simple updates the store:

case LOAD_ITEMS:
  console.log(action.items);
  return action.items;

Aucun commentaire:

Enregistrer un commentaire