jsdom-global icon indicating copy to clipboard operation
jsdom-global copied to clipboard

Add support for SVGElement?

Open joerattz opened this issue 2 years ago • 2 comments

The jsdom package appears to support SVGElement now. Can support for SVGElement be added to jsdom-global?

Thanks!

joerattz avatar Dec 03 '21 22:12 joerattz

Try updating jsdom (not jsdom-global) in your project. Hope it helps!

On Sat, 4 Dec 2021, 9:06 am Joe Rattz, @.***> wrote:

The jsdom package appears to support SVGElement now. Can support for SVGElement be added to jsdom-global?

Thanks!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rstacruz/jsdom-global/issues/60, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAASFEL4CY5T7U4A7S6WSTLUPE5NPANCNFSM5JKW6FKQ .

rstacruz avatar Dec 03 '21 23:12 rstacruz

Thanks for responding. I am using the latest version of jsdom, 18.1.1, which was released 15 days ago.

And jsdom does appear to have support for SVGElement. While non-existent in the source, presumably because it is generated, there is a file named SVGElement.js in node_modules\jsdom\lib\jsdom\living\generated. Not sure what that file gets generated from.

It appears to me that the problem is caused by jsdom-global's keys.js file's LIVING_KEYS array missing SVGElement. If I add SVGElement to the array, my error message goes away. Just noticed I didn't provide the error message.

The error message is "ReferenceError: SVGElement is not defined"

While adding "SVGElement" to the LIVING_KEYS array makes the error message go away, I'm not completely sure that alone is a proper fix because I don't know what all needs to be done for SVGElement to be properly supported. I'm just Forrest Gumping my way through this.

I have worked around this by adding the following line of code to a module that gets run for all my tests:

global.SVGElement = window.SVGElement;

I've seen someone online propose this as a work-around and it does remove the error message but I feel like my work-around is better.

global.SVGElement = global.Element;

But I'm hoping jsdom-global will be updated to properly support SVGElement by adding the LIVING_KEYS entry and updating anything else needed. Also, if this is done, there's a comment right above the LIVING_KEYS array that is no longer correct.

Thanks.

joerattz avatar Dec 06 '21 16:12 joerattz