tleunen / react-mdl

React Components for Material Design Lite
https://tleunen.github.io/react-mdl/
MIT License
1.76k stars 255 forks source link

Problems in NodeJS environment. #390

Open Fen1kz opened 8 years ago

Fen1kz commented 8 years ago

I have a problem in testing via mounting enzyme component. Problem line, for example (from extra/material.js):

if ('CustomEvent' in window && typeof window.CustomEvent === 'function') {
        ev = new CustomEvent('mdl-componentupgraded', {

This will fail in NodeJS, because CustomEvent is not defined in global scope, however window.CustomEvent is OK. Currently, I'm fixing this as doing

require('react-mdl/extra/material');  
global.Element = global.window.Element;  
global.CustomEvent = global.window.CustomEvent;  
global.Event = global.window.Event;  
global.NodeList = global.window.NodeList;  
global.Node = global.window.Node; 

However I don't feel this is right, it's preferable for me to not have this chunk of code at all, by changing problem line to

ev = new window.CustomEvent('mdl-componentupgraded', {
tleunen commented 8 years ago

I believe you might be able to skip the use of react-mdl/extra-material inside a nodejs env. Have you tried it?