当用户单击对话框上的“取消”按钮时,我正在尝试使用以下测试测试对话框的消失:
it("clicking on cancel hides the confirmation dialog", async() => {
render(<ConfirmationDialog />);
const cancelButton = screen.getByText("Cancel");
fireEvent.click(cancelButton);
await waitForElementToBeRemoved(() => screen.queryByText(/Cancel/i));
expect(screen.queryByText(/Cancel/i)).toBeNull();
});
但是上面的代码抛出了一个错误: TypeError: MutationObserver is not a constructor
24 | const cancelButton = screen.getByText("Cancel");
25 | fireEvent.click(cancelButton);
> 26 | await waitForElementToBeRemoved(() => screen.queryByText(/Cancel/i));
| ^
27 | expect(screen.queryByText(/Cancel/i)).toBeNull();
28 | });
29 | });
有人可以帮助我理解这个问题,因为我是测试库的新手。提前致谢。