redux-things/redux-actions-assertions

Add possibility to assert action by type and discard payload

TristanWright opened this issue · 1 comments

For some async actions, instead of replicating a lot of data I'd just like to check that an action of a certain type is being dispatched. I'll make a PR for it if you think it's a good idea.

From one side it is a good idea.
From another side - it could hide errors because you will ensure that you are triggering action, but payload can have a mistype.
For example date instead of data: { type: 'some type', date: {...} }

What I can propose is to extend .toDispatchActions with a comparator as second arguments, same as lodash does. Then you will be able to do different types of checks, like :

expect(myAction())
  .toDispatchActions([ { type: 'a' }, { type: 'b' } ]);

expect(myAction())
  .toDispatchActions(
    [ { type: 'a' }, { type: 'b' } ],
    (actual, expected) => actual.type === expected.type
  );

expect(myAction())
  .toDispatchActions(
    [ { type: 'a' }, { type: 'b' } ],
    (actual, expected) => actual.type === expected.type && actual.timestamp === expected.timestamp
  );