reactjs - Jest throws ReferenceError: SVGPathElement is not defined - Stack Overflow

I am using Jest in my React module and encountering an error where it cannot find the classes for SVG e

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

The error went away after migrating from jsdom to happy-dom.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744366941a4570751.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信