Difference between testSaga and expectSaga in redux-saga-test-plan
Asked Answered
D

1

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.

Dahlia answered 17/9, 2019 at 0:13 Comment(0)
C
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

Carlsen answered 17/9, 2019 at 5:10 Comment(3)
Thanks azundo. I reviewed the doc, so simply speaking, testSaga is stricter than expectSaga, does that mean we could use testSaga regardless?Dahlia
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.Carlsen
That makes sense. Thank you for explaining!Dahlia

© 2022 - 2024 — McMap. All rights reserved.