yiminghe/dom-align

ReferenceError: getComputedStyle is not defined

jsherin opened this issue · 2 comments

After the 1.8.1 update our tests which use jsdom fail with the error:

ReferenceError: getComputedStyle is not defined
    at getVisibleRectForElement (/home/developer/workspace/main/pvc-core/webui/node_modules/dom-align/lib/getVisibleRectForElement.js:83:19)
    at isOutOfVisibleRect (/home/developer/workspace/main/pvc-core/webui/node_modules/dom-align/lib/align/alignElement.js:26:63)
    at alignElement (/home/developer/workspace/main/pvc-core/webui/node_modules/dom-align/lib/align/alignElement.js:36:34)
    at Align._this.forceAlign (/home/developer/workspace/main/pvc-core/webui/node_modules/rc-align/lib/Align.js:88:47)
    at Align.componentDidMount (/home/developer/workspace/main/pvc-core/webui/node_modules/rc-align/lib/Align.js:107:12)
    at /home/developer/workspace/main/pvc-core/webui/node_modules/react-dom/lib/ReactCompositeComponent.js:262:25
    at measureLifeCyclePerf (/home/developer/workspace/main/pvc-core/webui/node_modules/react-dom/lib/ReactCompositeComponent.js:73:12)
    at /home/developer/workspace/main/pvc-core/webui/node_modules/react-dom/lib/ReactCompositeComponent.js:261:11
    at CallbackQueue.notifyAll (/home/developer/workspace/main/pvc-core/webui/node_modules/react-dom/lib/CallbackQueue.js:74:22)
    at ReactReconcileTransaction.close (/home/developer/workspace/main/pvc-core/webui/node_modules/react-dom/lib/ReactReconcileTransaction.js:78:26)

Is their a workaround for this?

getComputedStyle is accessed directly in the latest dom-align release instead of using window.getComputedStyle, workaround, mock getComputedStyle and make it globally accessible:

var getComputedStyle = () => {
  var style = {};
  style.getPropertyValue = () => {
    return 20;
  };
  return style;
};
global.getComputedStyle = getComputedStyle;

Thanks for report. Change to window.getComputedStyle instead.