question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceError: SVGPathElement is not defined

See original GitHub issue

Basics

  • Using Jest version 22.1.4, with TypeScript 2.6.2 and jsdom environment.
  • This seems to be a bug.

What is the current behavior?

When using path-data-polyfill.js, it uses SVGPathElement.prototype to add methods that were removed from SVG API in Chrome (i.e. getPathData, setPathData and others).

When running Jest with jsdom, it complains ReferenceError: SVGPathElement is not defined.

I made a quick search in jsdom source code and couldn’t find any mention to SVGPathElement

Not only SVGPathElement is missing but also SVGRectElement, SVGCircleElement, SVGEllipseElement, SVGLineElement, SVGPolylineElement and SVGPolygonElement.

As I’m using jsdom only for running Jest tests and compilation through tsc works fine, I guessed the right place to report this issue was in here - not in jsdom repo - please correct me if I am wrong.

What is the expected behavior?

I would expect any SVG basic element class to be present when running tests with Jest.

This is how my --debug did output config:

{
  "configs": [
    {
      "automock": false,
      "browser": false,
      "cache": true,
      "cacheDirectory": "/var/folders/lq/ztg_mkn935x1y5gmyw8cfw_80000gn/T/jest_dx",
      "clearMocks": false,
      "coveragePathIgnorePatterns": [
        "/node_modules/",
        "/test/",
        "/dist/",
        "/test/helpers/",
        "/test/test-examples/"
      ],
      "detectLeaks": false,
      "forceCoverageMatch": [],
      "globals": {},
      "haste": {
        "providesModuleNodeModules": []
      },
      "moduleDirectories": [
        "node_modules"
      ],
      "moduleFileExtensions": [
        "ts",
        "tsx",
        "js"
      ],
      "moduleNameMapper": {},
      "modulePathIgnorePatterns": [],
      "name": "e444587e65998f707a150efb3a23fdbc",
      "resetMocks": false,
      "resetModules": false,
      "restoreMocks": false,
      "rootDir": "/Users/setup/Working/my-lib",
      "roots": [
        "/Users/setup/Working/my-lib"
      ],
      "runner": "jest-runner",
      "setupFiles": [],
      "snapshotSerializers": [],
      "testEnvironment": "jest-environment-jsdom",
      "testEnvironmentOptions": {},
      "testLocationInResults": false,
      "testMatch": [],
      "testPathIgnorePatterns": [
        "/node_modules/"
      ],
      "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
      "testRunner": "/Users/setup/Working/my-lib/node_modules/jest/node_modules/jest-jasmine2/build/index.js",
      "testURL": "about:blank",
      "timers": "real",
      "transform": [
        [
          ".(ts|tsx)",
          "/Users/setup/Working/my-lib/node_modules/ts-jest/preprocessor.js"
        ]
      ],
      "transformIgnorePatterns": [
        "/node_modules/"
      ],
      "watchPathIgnorePatterns": []
    }
  ],
  "globalConfig": {
    "bail": false,
    "changedFilesWithAncestor": false,
    "collectCoverage": true,
    "coverageDirectory": "/Users/setup/Working/my-lib/coverage",
    "coverageReporters": [
      "json",
      "text",
      "lcov",
      "clover"
    ],
    "coverageThreshold": {
      "global": {
        "branches": 0,
        "functions": 0,
        "lines": 0,
        "statements": 0
      }
    },
    "detectLeaks": false,
    "expand": false,
    "globalSetup": null,
    "globalTeardown": null,
    "listTests": false,
    "mapCoverage": true,
    "maxWorkers": 3,
    "noStackTrace": false,
    "nonFlagArgs": [],
    "notify": false,
    "passWithNoTests": false,
    "rootDir": "/Users/setup/Working/my-lib",
    "runTestsByPath": false,
    "testFailureExitCode": 1,
    "testPathPattern": "",
    "testResultsProcessor": null,
    "updateSnapshot": "new",
    "useStderr": false,
    "verbose": null,
    "watch": false,
    "watchman": true
  },
  "version": "22.1.4"
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
probablyupcommented, Jan 24, 2018

Looks like it’s not implemented in JSDOM: https://github.com/tmpvar/jsdom/tree/master/lib/jsdom/living/nodes

You should definitely move this issue there, as they would be the ones to build support.

In the meantime, you can monkeypatch support in a setup file like this I think?

class SVGPathElement extends HTMLElement {}

window.SVGPathElement = SVGPathElement
0reactions
github-actions[bot]commented, May 13, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SVGPathElement is not defined #1387 - amcharts/amcharts4
Hello. Why an error occurs in amcharts 4 when conducting unit tests. I am using Vue-Cli 3. mocha-webpack (unit test) 1) Компонент Krs ......
Read more >
Jest - ReferenceError: SVGPathElement is not defined
I'm trying to run a Jest unit test to match snapshot, but there seems to be an issue with am4core. Does anyone have...
Read more >
ReferenceError: SVG is not defined - The Observable Forum
Hello! I'm trying to load ApexCharts.js in a notebook and I get the following error: ReferenceError: SVG is not defined Notebook reference ...
Read more >
jest referenceerror: global is not defined - You.com | The AI ...
When running Jest with jsdom, it complains ReferenceError: SVGPathElement is not defined . I made a quick search in jsdom source code and...
Read more >
SVG Works fine in borwser but not WP or Divi | WordPress.org
Uncaught ReferenceError: displayName is not defined at SVGPathElement.onmouseover (<anonymous>:2:1). I would usually separate the javascript (and CSS) out ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found