marcglasberg / async_redux

Flutter Package: A Redux version tailored for Flutter, which is easy to learn, to use, to test, and has no boilerplate. Allows for both sync and async reducers.
Other
230 stars 41 forks source link

Prevent dispatch of certain action types in tests #77

Closed kuhnroyal closed 4 years ago

kuhnroyal commented 4 years ago

I often have actions that dispatch new actions in after* functions, basically chaining a few actions. When unit testing I always have to mock everything for the whole action chain when I only want to test the first action. Is there a way to prevent the actual dispatch of these chained action in tests? StoreTester allows to ignore actions but that is only in regard to their validation.

kuhnroyal commented 4 years ago

I found a way by overriding dispatch* functions of the Store implementation and checking against an ignore list before calling super. Is this the recommended way?

marcglasberg commented 4 years ago

I never really had this problem of ignoring some actions. I guess you found a nice solution.

marcglasberg commented 4 years ago

@kuhnroyal

Just added your idea to AsyncRedux [version 2.12.0], and expanded it so that you can mock actions/reducers, not only disable them. Please have a look:

https://pub.dev/packages/async_redux#mocking-actions-and-reducers

kuhnroyal commented 4 years ago

Thanks @marcglasberg, this is perfect!