Make preact support jsdom
See original GitHub issueI’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:
- Created 7 years ago
- Comments:6 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Good news, the
Text
global is dropped in8.0
. Hoping to have a beta out this weekend 😃was wondering why i was getting
Text is undefined
… glad I found this issue (which led me to addingglobal.Text = win.Text
in my test / jsdom config.