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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744366941a4570751.html
评论列表(0条)