Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ReferenceError:未定义html2pdf(JSPDF)_Javascript_Reactjs_Enzyme_Jspdf_Shallow Copy - Fatal编程技术网

Javascript ReferenceError:未定义html2pdf(JSPDF)

Javascript ReferenceError:未定义html2pdf(JSPDF),javascript,reactjs,enzyme,jspdf,shallow-copy,Javascript,Reactjs,Enzyme,Jspdf,Shallow Copy,当我使用浅层渲染编写单元测试时,我遇到了以下错误 When I comment out my unit test code whole jspdf code works fine. I am surprised why it is failing only when I execute unit test like below - import { expect } from "chai"; import { shallow } from "enzyme";

当我使用浅层渲染编写单元测试时,我遇到了以下错误

    When I comment out my unit test code whole jspdf code works fine.
    I am surprised why it is failing only when I execute unit test like below -

    import { expect } from "chai";
    import { shallow } from "enzyme";
    import "mocha";
    import * as React from "react";

    const jsdom = require("jsdom-global");
    jsdom();
    import App from "../src/app";

    describe("<App/>", () => {
      it("should do a shallow render of <Provider/>", () => {

        const elem = shallow(<App/>); //this line is creating issue
        expect(elem.find("Provider")).to.have.length(1);
      });
    });
ReferenceError:未定义html2pdf at/PathToProject/node_modules/jspdf/dist/jspdf.min.js:202:16291

    When I comment out my unit test code whole jspdf code works fine.
    I am surprised why it is failing only when I execute unit test like below -

    import { expect } from "chai";
    import { shallow } from "enzyme";
    import "mocha";
    import * as React from "react";

    const jsdom = require("jsdom-global");
    jsdom();
    import App from "../src/app";

    describe("<App/>", () => {
      it("should do a shallow render of <Provider/>", () => {

        const elem = shallow(<App/>); //this line is creating issue
        expect(elem.find("Provider")).to.have.length(1);
      });
    });
当我注释掉我的单元测试代码时,整个jspdf代码都可以正常工作。
我很惊讶为什么只有当我执行下面这样的单元测试时它才会失败-
从“chai”导入{expect};
从“酶”中导入{shall};
进口“摩卡”;
从“React”导入*作为React;
const jsdom=require(“jsdom全局”);
jsdom();
从“./src/App”导入应用程序;
描述(“,()=>{
它(“应该做一个浅渲染”,()=>{
const elem=shallow();//此行正在创建问题
expect(elem.find)(“Provider”).to.have.length(1);
});
});

注意:在执行单元测试之前,一切都很好。所有jspdf功能都运行良好。但是,当我通过编写shallow来执行单元测试时,它就会抛出这个错误。

当前回购协议中有一个未解决的问题。第二个答复中提到的解决方法可能值得一试。 如果不是的话,这个问题似乎是在v1.5.1中引入的,我发现让jspdf与酶很好地结合的唯一方法就是回到v1.4.1。在1.4.1中,我在运行测试时遇到了一个不同的错误*,但它不会导致测试失败

*错误未实现:HTMLCanvasElement.prototype.getContext(不安装canvas npm包)-安装canvas npm包无法解决此问题