admin管理员组文章数量:1403527
I am using Jest in my React module and encountering an error where it cannot find the classes for SVG elements like SVGPathElement
and SVGPolylineElement
. The specific error message is:
ReferenceError: SVGPathElement is not defined
Here is the sample code that reproduces the issue:
import '@testing-library/jest-dom';
class MyClass extends SVGPathElement {
}
it('first test', () => {
});
I have defined several prototypes for these SVG classes in my application, so I prefer not to redefine them in my Jest tests like this:
class SVGPathElement extends SVGElement {}
window.SVGPathElement = SVGPathElement as any
Is there a better way to configure Jest or handle this issue without manually redefining these SVG classes? Any advice or solutions would be greatly appreciated.
I am using Jest in my React module and encountering an error where it cannot find the classes for SVG elements like SVGPathElement
and SVGPolylineElement
. The specific error message is:
ReferenceError: SVGPathElement is not defined
Here is the sample code that reproduces the issue:
import '@testing-library/jest-dom';
class MyClass extends SVGPathElement {
}
it('first test', () => {
});
I have defined several prototypes for these SVG classes in my application, so I prefer not to redefine them in my Jest tests like this:
class SVGPathElement extends SVGElement {}
window.SVGPathElement = SVGPathElement as any
Is there a better way to configure Jest or handle this issue without manually redefining these SVG classes? Any advice or solutions would be greatly appreciated.
Share Improve this question edited Mar 22 at 8:23 Mohamad Mehdi Rajaei asked Mar 21 at 8:10 Mohamad Mehdi RajaeiMohamad Mehdi Rajaei 311 silver badge8 bronze badges1 Answer
Reset to default 0The error went away after migrating from jsdom to happy-dom.
本文标签: reactjsJest throws ReferenceError SVGPathElement is not definedStack Overflow
版权声明:本文标题:reactjs - Jest throws ReferenceError: SVGPathElement is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744366941a2602825.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论