lundi 19 septembre 2016

How to unit test a method that is dependent on another?

I have a React and Redux project I'm trying to unit test with Chai testing framework. Right now I'm writing a test for a reducer I have, and several of actions this reducer handles call helper methods. Here is an example:

formsReducer.js:

import * as types from '../constants/actionTypes';
import objectAssign from 'object-assign';
import initialState from './initialState';
import formsHelper from '../utils/FormsHelper';
export default function formsReducer(state = initialState.forms, action) {
  switch (action.type) {
    case types.UPDATE_PRODUCT: {
        let formBlueprints = formsHelper.getFormsByProductId(action.product.id);
        formBlueprints = formsHelper.addOrRemoveMnDisclosure(formBlueprints, action.stateOfResidence.id);
        return objectAssign({}, state, {blueprints: formBlueprints, instances: []});
    }
  }
}

As you can see, if I test this method I'm dependent on the formsHelper.getFormsByProductId and formsHelper.addOrRemoveMnDisclosure methods to pass as well. How should I test this reducer/action? Should I make a separate set of test data that can be returned from these methods when a certain product.id is passed to these methods?

Aucun commentaire:

Enregistrer un commentaire