You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a component which relies on refs and Scrollbooster (see below). When trying to mount the component with Enzyme I get an error saying:
at processImmediate (timers.js:658:5) ReferenceError: Element is not defined
at new t (/home/vikenfalk/third-party-client/tp-client/node_modules/scrollbooster/dist/webpack:/ScrollBooster/src/index.js:76:70)
If I log the reference that I'm passing to the Scrollbooster it looks fine and identical to what I can see when I run the actual application. The error seems to be related to JSDOM, but I'm wondering if anybody knows a way around this issue so that I can mount the component and test the calculations within the UseEffect function?
constProgressBarScroller=(props)=>{const[progressbarWrapperRef,progressBarTaskRef,progressBarRef]=[useRef(null),useRef(null),useRef(null)];constgetElementWidth=(refName)=>refName.current.getBoundingClientRect().width;useEffect(()=>{if(!progressBarTaskRef.current||!progressBarRef.current||!progressbarWrapperRef.current)return;consttaskWidth=getElementWidth(progressBarTaskRef);constprogressBarWidth=getElementWidth(progressBarRef);constprogressbarWrapperWidth=getElementWidth(progressbarWrapperRef);constmiddleOfActiveTask=(props.currentTaskIndex+1)*taskWidth-taskWidth/2;constrequestedX=middleOfActiveTask-progressbarWrapperWidth/2;constmaxPossibleX=progressBarWidth-progressbarWrapperWidth;constscroller=newscrollBooster({viewport: progressbarWrapperRef.current,direction: 'horizontal',scrollMode: 'transform',friction: 0.2});/** * returns 0 if requested X position is lower than minimum. * returns the highest possible X position if requested X is higher than maximum. * Otherwise returns requested X position. * @returns {number} */constgetValidXPosition=()=>{returnrequestedX<=0 ? 0
: requestedX>=maxPossibleX ? maxPossibleX
: requestedX;};(functionmoveToDefaultPosition(){scroller.setPosition({x: getValidXPosition(),y: 0});})();//Cleans up ScrollBooster on unmountreturn()=>{scroller.destroy();};},[]);return(<divclassName={'cs-progressbar'}ref={progressbarWrapperRef}><ulclassName={`cs-progressbar__list`}ref={progressBarRef}>{props.tasks.map((task,index)=>{return(<ProgressBarTask{...task}key={task.id}innerRef={props.currentTaskIndex===index
? progressBarTaskRef
: null}/>);})}</ul></div>);};
library
version
enzyme
3.11.0
react
16.13.1
react-dom
16.13.1
react-test-renderer
17.0.1
scrollbooster
2.3.0
The text was updated successfully, but these errors were encountered:
Hi!
I have a component which relies on refs and Scrollbooster (see below). When trying to mount the component with Enzyme I get an error saying:
If I log the reference that I'm passing to the Scrollbooster it looks fine and identical to what I can see when I run the actual application. The error seems to be related to JSDOM, but I'm wondering if anybody knows a way around this issue so that I can mount the component and test the calculations within the UseEffect function?
The text was updated successfully, but these errors were encountered: