mercredi 26 juillet 2017

Javascript testing in general

Let's say I want to test the following for example:

import {fetchResourceFromBackend} from './myfetch';

const fetchSomething = (dispatch) => {

  dispatch(2);

  return fetchResourceFromBackend('/api/abc').then( result => {
    dispatch(3);
  });
};

fetchResourceFromBackend is some complicated function. How can I test this (any tool and method recommendations, I could use mocha and sinon but some pattern is needed).

Is my only option to provide fetchResourceFromBackend as an argument to fetchSomething so I can mock it?

Aucun commentaire:

Enregistrer un commentaire