react-testing-library icon indicating copy to clipboard operation
react-testing-library copied to clipboard

Mocked axios get call response is getting set after rendering of component

Open jayneesh opened this issue 3 years ago • 4 comments

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

jayneesh avatar Sep 18 '22 13:09 jayneesh

I guess you should wait for the content either using await.findBy or await waitFor

mstangret avatar Sep 18 '22 16:09 mstangret

@mstangret i am doing await waitFor(()=>screen.getByRole("table")); I am getting a table but there are no rows

jayneesh avatar Sep 18 '22 16:09 jayneesh

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.

mstangret avatar Sep 18 '22 16:09 mstangret

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 :)

MatanBobi avatar Sep 20 '22 10:09 MatanBobi

Closing since this is better handled in support channels (e.g. our discord server) and no concrete repro was provided.

eps1lon avatar Oct 08 '22 09:10 eps1lon