mardi 26 juin 2018

Writing a test for a conditional block in a reducer/action creator

Say I have a reducer or action creator that has some conditional logic in it and depending on the logic it will either call window.location.assign or dispatches an action. how can I mock out/change the const (which is local to the function) which causes it to either jump into the if or else block

literally googled so much for this and cannot find it anywhere. anyone got any ideas? even pointing me to docs

literally all I want to test is:

const url = getState().url
if(url){
  window.location... // one test for this
} else {
  dispatch({ type: MY_ACTION }) //a second test for this
}

why the heck is it so hard to find any docs or examples on this

Aucun commentaire:

Enregistrer un commentaire