'How many render operations does act() support?
I am using act
function from library https://testing-library.com/docs/react-testing-library/intro/.
At this point I have something like this:
await act(async () => {
page = renderPage([mockData, mockData2]);
});
await act(async () => {
onLoadSuccessFn?.({ numPages: 15 } as PDFDocumentProxy);
await waitForExpect(() => {
expect(page?.find('[id*="idToBeFound"]')).toBeTruthy();
});
});
In the first act I am waiting for the page/component to be rendered. In the second act I am calling onLoadSuccessFn
, which will trigger the rendering of another component.
However, if I group the 2 pieces of code(render of the component and function call described above) under the same act, my test will fail, basically because only one statement will be executed(out of the 2)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|