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.

Make preact support jsdom

See original GitHub issue

I’m working on fixing a test suite for React so it works with Preact. The original suite uses jsDom, but with Preact it gave some errors. The errors are caused by Preact assuming some globals exist and it can be easily fixed in userland code, like this:

jsdom.env('<!doctype html><html><head></head><body></body></html>', (error, window) => {
  if (!error) {
    global.window = window;
    global.document = window.document;
    // preact tests for SVGElement, but jsdom does not support it
    // https://github.com/tmpvar/jsdom/issues/1423
    global.SVGElement = function(){};
    // Preact tests for Text, supported by jsdom
    global.Text = window.Text
  }

  done(error);
});

Still’I think it may be worth it to safeguard these tests. I.s.o:

if (x instanceof SVGElement)

write:

if (typeof SVGElement == 'function' && (x instanceof SVGElement))

It’s a few more bytes but I think being compatible out of the box with jsDom would be a good thing for Preact.

Ideas?

Issue Analytics

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

github_iconTop GitHub Comments

6reactions
developitcommented, Feb 25, 2017

Good news, the Text global is dropped in 8.0. Hoping to have a beta out this weekend 😃

2reactions
peter-moulandcommented, Mar 28, 2017

was wondering why i was getting Text is undefined… glad I found this issue (which led me to adding global.Text = win.Text in my test / jsdom config.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing with Preact Testing Library
The Preact Testing Library is a lightweight wrapper around preact/test-utils . It provides a set of query methods for accessing the rendered DOM...
Read more >
Getting Started | Preact: Fast 3kb React alternative with the ...
Your project could need support for the wider React ecosystem. To make your application compile, you might need to disable type checking on...
Read more >
Libraries & Add-ons | Preact
Collection of libraries and addons that work well with Preact.
Read more >
Unit Testing with Enzyme | Preact: Fast 3kb React alternative ...
Enzyme supports tests that run in a normal or headless browser using a tool such as Karma or tests that run in Node...
Read more >
Switching to Preact (from React)
1. Install Preact · 2. JSX Pragma: transpile to `h()`. Via Babel; Via Comments; Via Bublé · 3. Update any Legacy Code ·...
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