Skip to content

Testing is Done Right #518

@3LOK

Description

@3LOK

Hi,

My comment is about: https://redux-saga.github.io/redux-saga/docs/advanced/Testing.html

I think the way you see testing sagas is wrong and puts emphasis on exact 'implementation', and not 'result'.

The way you do tests: Check the call for each 'yield', and muck a return value to that yield. In this case if I change the implementation of my saga (in such a way that doesn't affect the results), I need to change me tests. Any refactoring of code will necessarily mean changing the tests.

My view is that your tests check that you implemented your saga in a very very specific way and not that the saga is doing what it needs to be doing.

The way we write test for our sagas is:

  1. Set up a test store with a specific scenario. Test store includes a reducer that interacts with actions that are fired by the saga.
  2. Run the saga using the standard redux-saga framework.
  3. See the side effects (actions that were sent).

I think this way of testing puts the emphasis where it needs to be. If we refactor the saga, and it still does exactly what it needs to do, the tests won't need to change (making the tests helpful for refactoring).

WDYT?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions