小编jag*_*h c的帖子

玩笑错误 - 未实现:在锚元素上触发单击事件时进行导航(哈希更改除外)

我已经使用 jest 版本、26.0.0react-testing-library 和 node 版本编写了单元测试14.2.0。下面是我的 React 功能组件,它有一个按钮,单击后会发出 ajax 调用来下载报告文件。

const ReportListTable = () => {
    const { downloadReports } = useReports();

    const onClickDownload = () => {
        let fileName = `Report.zip`;
        downloadReports()
            .then((response) => response.arrayBuffer())
            .then((data) => {
                const blob = new Blob([data], { type: "octet/stream", endings: "native" });
                const url = window.URL.createObjectURL(blob);
                const anchor = document.createElement("a");
                anchor.setAttribute("href", url);
                anchor.setAttribute("download", fileName);
                anchor.click();
                window.URL.revokeObjectURL(url);
            })
            .catch((error?: Error | Response) => {
                if (error instanceof Error) { …
Run Code Online (Sandbox Code Playgroud)

unit-testing reactjs jestjs react-testing-library

12
推荐指数
1
解决办法
1万
查看次数