I write a test for a seletion and I get this warning. In my test I'm waiting for the end of the act. Why I get this error?
Warning: You seem to have overlapping act() calls, this is not supported. Be sure to await previous act() calls before making a new one.
test('Selection should be have the correct number of options', async () => {
const leftClick = { button: 0 };
const { options } = makeSUT();
const selection = screen.getByLabelText('MultiSelection');
// open all option
act(() => {
userEvent.click(selection, leftClick);
});
// await wait();
options.forEach(async (option, index) => {
if (index === 0) {
expect((await screen.findAllByText(option.label)).length).toEqual(1);
} else {
expect((await screen.findAllByText(option.label)).length).toEqual(1);
}
});
});
Thank you
act
needs anawait
. RTL methods are wrapped inact
so your assertion is using anact
call before the first one has resolved. – Rewire