Using Jest and Enzyme.

The Bug is happening for this test.

@threepointone @gaearon
Please any input into why this is the case. Thank you.
@SarpongAbasimi Did you try wrapping the thing that causes the update (form.simulate('submit')) in act like the warning message says?
@bvaughn Yes but that didn't work.
Share your test code so one of us can run it? Screenshots of code are of limited use :smile:
When you use synchronous act function, because the API call is asynchronous, the submit handler is completed; however, that doesn't mean that the API call is finished within a single execution cycle. So, if you set state after the API response, it is going to be executed outside the act call. This is still the case when you mock your API calls because the function itself is asynchronous. I think you need to use asynchronous version of act:
it(..., async () => {
// mock implementation etc
await act(async () => {
form.simulate('submit');
});
}
Thank you @GasimGasimzada you are a legend 馃憫.
And thanks for explaining it to me, really helpful.
I will now close this.
Most helpful comment
When you use synchronous act function, because the API call is asynchronous, the submit handler is completed; however, that doesn't mean that the API call is finished within a single execution cycle. So, if you set state after the API response, it is going to be executed outside the
actcall. This is still the case when you mock your API calls because the function itself is asynchronous. I think you need to use asynchronous version ofact:Testing Recipe for Data Fetching