Every similar question I've looked at doesn't seem to be able to provide the right combination to make the test execution happy. Hoping someone can see what I am missing...
The test code
it('2 checkmarks are checked after clicking on them and unchecked when clicked a 2nd time', async () => {
const userViewer = userEvent.setup();
const testComponent = render(<TestContainer />);
// open accordion item
const expandAccordionItemControl = testComponent.getByRole('button', { name: /Add groups/i });
await userViewer.click(expandAccordionItemControl);
// click on 2 row checkboxes
let checkedRows = testComponent.queryAllByRole('checkbox', { checked: true });
expect(checkedRows.length).toBe(0);
const uncheckedRows = testComponent.getAllByRole('checkbox', { checked: false });
const checkboxTwo = uncheckedRows[1];
const checkboxFour = uncheckedRows[3];
await userViewer.click(checkboxTwo);
await userViewer.click(checkboxFour);
// two row checkboxes are checked
checkedRows = testComponent.queryAllByRole('checkbox', { checked: true });
expect(checkedRows.length).toBe(2);
// uncheck checked rows
// await Promise.all(checkedRows.map((cb) => userViewer.click(cb))); <-------- returns error
await act(async () => {
await Promise.all(checkedRows.map((cb) => userViewer.click(cb))); // <--------- tried this but still same error
});
// confirm all rows are unchecked
checkedRows = testComponent.queryAllByRole('checkbox', { checked: true });
expect(checkedRows.length).toBe(0);
});
For now, my solution is to just hardcode both uncheck clicks...
const checkedBoxTwo = checkedRows[0];
const checkedBoxFour = checkedRows[1];
await userViewer.click(checkedBoxTwo);
await userViewer.click(checkedBoxFour);
but I was really hoping to just let a loop handle this. Anyone have any ideas?