react-testing-library
react-testing-library copied to clipboard
Mocked axios get call response is getting set after rendering of component
IN my react component i have a react data table. the data of which is fetched from axios get call. for testing of this component i have mocked the response which we get from axios get call . The mocked response is coming correctly but the table is coming empty . How to get the table rendered
I guess you should wait for the content either using await.findBy or await waitFor
@mstangret i am doing await waitFor(()=>screen.getByRole("table")); I am getting a table but there are no rows
I can only guess without knowing the exact code. Maybe the table is rendered before the network response is received and this is why your test finishes before actual response data is presented? If you mock the network response, can’t you wait for a particular piece of data?
Nevertheless, it doesn’t sound like a RTL issue.
Hi @jayneesh.. As @mstangret, it looks like you need to await for something but we won't be able to help without a reproducible example.
In fact, these kind of questions are better asked in our discord server or on stackoverflow.
I'm keeping this open for a couple of days hoping you'll attach a reproducible example, if you won't I'll close it and recommend again to ask this in the channels I attached above :)
Closing since this is better handled in support channels (e.g. our discord server) and no concrete repro was provided.