jeudi 11 janvier 2018

How to easily test redux-observable epic that emits an action after 5 minutes?

I have an epic that emits SOME_OTHER_ACTION when 5 minutes have passed after SOME_ACTION (using delay operator). I want to use jest or sinon useFakeTimers method to be able to do the following: dispatch an action, wait 5 minutes and test if another action was dispatched. I really don't want to use marble diagrams, or inject TestSchedulers. I also don't want to wait 5 minutes of real time.

const timeBefore = new Date().getTime() / 1000;
store.dispatch(SOME_ACTION);
// wait 5 minutes
jest.runTimersToTime(5 * 60 * 1000);
expect(store.getActions()).toEqual([ SOME_ACTION, SOME_OTHER_ACTION ]);
expect(store.getActions()[1].time).toEqual(timeBefore + 5 * 60 * 1000);

Aucun commentaire:

Enregistrer un commentaire