Giter VIP home page Giter VIP logo

Comments (7)

thebuilder avatar thebuilder commented on June 5, 2024 24

After upgrading to version 2.x, my tests started failing with this error message.

It's caused by this piece of code:

    /**
     * Update the SVG dimensions and path length
     */
    SVGVisualElement.prototype.measure = function () {
        try {
            this.dimensions =
                typeof this.element.getBBox ===
                    "function"
                    ? this.element.getBBox()
                    : this.element.getBoundingClientRect();
        }
        catch (e) {
            // Most likely trying to measure an unrendered element under Firefox
            this.dimensions = { x: 0, y: 0, width: 0, height: 0 };
        }
        if (isPath(this.element)) {
            this.totalPathLength = this.element.getTotalLength();
        }
    };

With this.element.getTotalLength(); throwing the error, since getTotalLength doesn't exist on the SVGElement.
What changed, since it was working in version 1.x?

For now I've solved it by adding the following to my test setup file, to make sure it's defined:

if (!SVGElement.prototype.getTotalLength) {
  SVGElement.prototype.getTotalLength = () => 1;
}

from motion.

mattgperry avatar mattgperry commented on June 5, 2024

This is a bug in JSDom: jsdom/jsdom#1330

I'm going to leave this ticket open as we can probably duck-type this in https://github.com/Popmotion/popmotion/tree/master/packages/stylefire so it at the very least doesn't break tests.

from motion.

rhogeranacleto avatar rhogeranacleto commented on June 5, 2024

πŸŽ‰ πŸŽ‰

from motion.

matt-d-rat avatar matt-d-rat commented on June 5, 2024
if (!SVGElement.prototype.getTotalLength) {
  SVGElement.prototype.getTotalLength = () => 1;
}

Yep, experiencing the same problem after upgrading framer-motion from v1.10.3 to v2.3.0. This happens only when using JSDOM (with Enzyme) while under test. Everything works as expected in a standard browser environment.

Thanks for the snippet, that helped me to work around the problem for the time being.

from motion.

georgekrax avatar georgekrax commented on June 5, 2024

Any update on this issue, except including the above snippet code?

from motion.

GuidovdRiet avatar GuidovdRiet commented on June 5, 2024

Also experience this issue, this error occurred in a component: Error: Uncaught [TypeError: this.element.getTotalLength is not a function]

version: 3.2.2-rc.1

from motion.

paramsinghvc avatar paramsinghvc commented on June 5, 2024

Isn't there a proper polyfill for extending SVG base classes like SVGGeometryElement etc to include in test environments?

from motion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.