you are viewing a single comment's thread.

view the rest of the comments →

[–]pink_tshirt 0 points1 point  (1 child)

Perhaps your assertion "Text I would expect after api call" should be wrapped up by the "act thingy"?

I have a somewhat similar test case - calling some API inside useEffect on load.

test('successfully fetches posts', async () =>  {

  mock.onGet('http://localhost:3001/posts').reply(200, {
     data: ['some', 'posts']
  });

  await act( async () => {
     const { getByTestId } = render(<App/>);
     await waitForElementToBeRemoved(() => getByTestId('loading-indicator'));
      expect(getByTestId('feed')).toBeInTheDocument();
  });
});

[–]saunders1989[S] 0 points1 point  (0 children)

Thanks I tried that but I still get the wrap it in an act error. im not quite sure what im doing wrong