gpt4 book ai didi

reactjs - 打开和关闭对话框模式并等待通过提供程序的响应

转载 作者:行者123 更新时间:2023-12-04 12:41:54 25 4
gpt4 key购买 nike

使用 React 测试库来测试对话框提供程序。我可以让它打开,并在它出现时断言 - 但由于某种原因我无法在测试中关闭它。我需要重新渲染吗?

test('await the closing or confirming of the modal', async () => {
const { debug, getByText, queryByText } = render(
<DialogProvider>
<Test />
</DialogProvider>,
);
const openDialogButton = getByText(/click me/i);
fireEvent.click(openDialogButton);
await wait(() => getByText(/ok/i));
fireEvent.click(getByText(/ok/i));
debug();
});


function Test() {
const confirm = useConfirmation();
return (
<button
onClick={() => {
confirm({ variant: 'info' });
}}
>
click me
</button>
);
}

最佳答案

显然,以下似乎有效

  await waitForElement(() => getByText(/ok/i));
fireEvent.click(getByText(/ok/i));
await waitForElementToBeRemoved(() => queryByText(/ok/i));
expect(queryByText(/ok/i)).toBeNull();

关于reactjs - 打开和关闭对话框模式并等待通过提供程序的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58031532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com