Testing flow functions in Jest #2032
-
Question
Can someone please help me ? :( I have some nested Promises, basically, on the success of the first one, I am making another request and so on. Unfortunately, when I want to test that, code coverage reports is showing me that I am only reaching the first call but then it's getting stuck in .then() ...it's not entering there, the success callback is not made. I read that this is because of "yield" which doesn't behave the same in test mode and it's not waiting for the response to come. In the store, all my fetching functions are defined as follows:
Please, how would you make this work in tests? Using Jest and Enzyme/RTL |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
You should be able to remove the
In testing you could
Hopefully that pseudocode should point you in the right direction. |
Beta Was this translation helpful? Give feedback.
-
My solution – remove the flow wrapper with jest.spyOn:
And now use it before creating a store:
|
Beta Was this translation helpful? Give feedback.
-
Hey @Claudiaapalagie - looks like we got some answers here. I am going to convert this from an issue to a discussion, and then I will invite you to mark one of the answers as the correct one, or feel free to ask for additional help. |
Beta Was this translation helpful? Give feedback.
You should be able to remove the
then
requirement as theyield
returns the resolved value. The syntax is very similar toasync/await
In testing you could
jest.mock('axios')
then mock theresolvedValue()
ofaxios
something like:Hopefully that pseudocode should point yo…