8

Is it correct to say that expectSaga is for integration testing and testSaga is for general assertions?

In reality, I can actually use them interchangeably for all my tests, so I am a bit confused about when to use which.

PhoenixPan
  • 536
  • 7
  • 19

1 Answers1

5

I think the subheading line from the README under Unit Testing [1] is the most concise explanation of when you would use testSaga vs expectSaga:

If you want to ensure that your saga yields specific types of effects in a particular order, then you can use the testSaga function.

If you don't care about this level of detail, especially the ordering bit, then expectSaga is less rigid and therefore less brittle to future changes in your sagas. But in some cases you need to be very specific about exactly which effects in which order, in which case you should use testSaga.

[1] https://github.com/jfairbank/redux-saga-test-plan#unit-testing

azundo
  • 5,902
  • 1
  • 14
  • 21
  • Thanks azundo. I reviewed the doc, so simply speaking, `testSaga` is stricter than `expectSaga`, does that mean we could use `testSaga` regardless? – PhoenixPan Sep 17 '19 at 06:04
  • 1
    Yes, I believe you could always choose to use `testSaga`. It's often just a bit more tedious if you have some effects you don't care about testing explicitly. And if you add steps in your saga you will have to update all affected tests so everything is a bit more brittle. – azundo Sep 17 '19 at 20:56
  • That makes sense. Thank you for explaining! – PhoenixPan Sep 17 '19 at 23:35