jeudi 8 février 2018

How when testing React Component in Jest I can wait until receives props again?

I need to test a HOC which fetches data and passes it to a wrapped component.

It passes props in a few steps as data is fetches asynchronously.

First wave of props contains loading , which I managed to test

Second wave of props contains data prop, but I don't know to wait untill it arrives. I need some sort of eventuallyHasProps thing..

I am using Jest, react-test-renderer.

Is there any way to achieve this avoiding setting manual timeouts?

Thanks

it("should receive data prop", () => {

  const WithFetch = withFetch("http://google.com", {}, fetchMock)(component);
  const tree = renderer.create(<WithFetch />).toTree();
  expect(fetchMock.mock.calls[0][0]).toBe("http://google.com");
  console.log(tree) // first wave of props

});

Aucun commentaire:

Enregistrer un commentaire