Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instanceof SVGGraphicsElement causes typeError #761

Closed
MarkLyck opened this issue Feb 17, 2023 · 1 comment · Fixed by #762
Closed

instanceof SVGGraphicsElement causes typeError #761

MarkLyck opened this issue Feb 17, 2023 · 1 comment · Fixed by #762
Labels
bug Something isn't working

Comments

@MarkLyck
Copy link

MarkLyck commented Feb 17, 2023

Describe the bug
I am using happy-dom with vitest and I noticed after upgrading to antd@5.1.2 A bunch of my unit tests are failing with:

this error:

TypeError: Right-hand side of 'instanceof' is not an object
 ❯ _default node_modules/.pnpm/rc-util@5.27.1_biqbaboplfbrettd7655fr4n2y/node_modules/rc-util/lib/Dom/isVisible.js:14:15

At first I thought this was a bug in rc-util a library used by antd. But upon further inspection, it seems like it's a missing feature/case in happy-dom

This is the file that causes the error:

var _default = function _default(element) {
  if (!element) {
    return false;
  }
  if (element instanceof HTMLElement && element.offsetParent) {
    return true;
  }
  if (element instanceof SVGGraphicsElement && element.getBBox) {
    var _element$getBBox = element.getBBox(),
      width = _element$getBBox.width,
      height = _element$getBBox.height;
    if (width || height) {
      return true;
    }
  }
  if (element instanceof HTMLElement && element.getBoundingClientRect) {
    var _element$getBoundingC = element.getBoundingClientRect(),
      _width = _element$getBoundingC.width,
      _height = _element$getBoundingC.height;
    if (_width || _height) {
      return true;
    }
  }
  return false;
};

The part that is causing the error using happy-dom is element instanceof SVGGraphicsElement. If I comment out this if statement all of my unit tests will pass without issues.

To Reproduce
Steps to reproduce the behavior:

  1. Create a file that uses instanceof SVGGraphicsElement
  2. Run it in a test environment using happy-dom@8.4.3
  3. See error

Expected behavior
parsing instanceof SVGGraphicsElement should not cause an error.

Device:

  • OS: MacOS
  • Browser: node
  • Version: "happy-dom": "8.4.3",

Temporary solution
For now I have switched back to use JSdom where this problem does not occur. Will set up happy-dom again once this issue is resolved.

@capricorn86
Copy link
Owner

Thank you for reporting @MarkLyck! 🙂

Big thanks to @btea for contributing with a fix! 🌟

You can read about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v8.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants