![](/img/trans.png)
[英]JsPDF Uncaught ReferenceError: jsPDF is not defined"
[英]ReferenceError: html2pdf is not defined (JSPDF)
使用淺渲染編寫單元測試時,出現錯誤提示
ReferenceError:在/PathToProject/node_modules/jspdf/dist/jspdf.min.js:202:16291上未定義html2pdf
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功能都可以正常工作。 但是,一旦我通過淺寫執行單元測試,就會拋出此錯誤。
回購https://github.com/MrRio/jsPDF/issues/2462中目前存在一個未解決的問題。 第二個答復中提到的解決方法可能值得一試。 如果不是,這個問題似乎是在v1.5.1中引入的,而我發現讓jspdf與酶完美結合的唯一方法是回到v1.4.1。 在1.4.1上,運行測試時出現不同的錯誤*,但它不會導致測試失敗。
*錯誤未實現:HTMLCanvasElement.prototype.getContext(不安裝canvas npm包) -並且無法通過安裝canvas npm包解決
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.