1

callback inside useEffect not executing in JEST testing?Do I have to wait or something else. Repeat-callback inside useEffect not executing in JEST testing?Do I have to wait or something else. Repeat-callback inside useEffect not executing in JEST testing?Do I have to wait or something else.

1 Answer 1

1

Judging by the names of your function calls, yes, you would have to wait. fetch implies that you are performing an ansynchronous (a promise) call for data. That would, most likely, set some form of state. Doing that would rerender something (which takes a moment). Waiting for data changes is one of the hardest bits to wrap your head around when writing testing.

Sign up to request clarification or add additional context in comments.

9 Comments

I am new in JEST testing.So can you please tell me how I can wrap the test for wait?
it("check for TrendsPageContainer", async () => { const props = { history: {}, location: {}, activeLang: "hi", activeLangEn: "Hindi", match: { params: {} } }; const component = await renderer.create( <Provider store={store}> <Router> <TrendsPageContainer {...props} /> </Router> </Provider> ); const tree = component.toJSON(); expect(tree).toMatchSnapshot(); });
this is not working
Yes I am using React-Testing-Library
it("check for TrendsPageContainer", async () => { const props = { history: {}, location: {}, activeLang: "hi", activeLangEn: "Hindi", match: { params: {} }, }; const component = renderer.create( <Provider store={store}> {" "} <Router> {" "} <TrendsPageContainer {...props} />{" "} </Router>{" "} </Provider> ); const tree = component.toJSON(); await waitFor(() => { expect(tree).toMatchSnapshot(); }); });
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.