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?
Hey @Download - I actually removed the dependency on SVGElement in [email protected]. It's beta though, so npm i -S preact@beta.
As for Text, I'm looking into that now. It's the same type of check as SVGElement, so I might end up switching from node instanceof Text to typeof node.wholeText!=='undefined.
Good news, the Text global is dropped in 8.0. Hoping to have a beta out this weekend :)
Great job @developit !
Thanks a lot!
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.
@peter-mouland Good to hear - setting that constructor will keep working in 8.0, just it won't be necessary anymore :)
Fixed in 8.
Most helpful comment
Good news, the
Textglobal is dropped in8.0. Hoping to have a beta out this weekend :)