From 29a7f299a11400c2d23d6c6f5375d3f947968159 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Mon, 26 Mar 2018 21:56:39 +0300 Subject: [PATCH] tests: workaround perfectscroll importing issue in jest --- src/common-elements/perfect-scrollbar.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/common-elements/perfect-scrollbar.tsx b/src/common-elements/perfect-scrollbar.tsx index 3e574fb0..40ae4dcc 100644 --- a/src/common-elements/perfect-scrollbar.tsx +++ b/src/common-elements/perfect-scrollbar.tsx @@ -1,9 +1,17 @@ import * as React from 'react'; -import { default as PerfectScrollbarConstructor } from 'perfect-scrollbar'; +import PerfectScrollbarType, * as PerfectScrollbarNamespace from 'perfect-scrollbar'; import psStyles from 'perfect-scrollbar/css/perfect-scrollbar.css'; import styled, { injectGlobal } from '../styled-components'; +/* + * perfect scrollbar umd bundle uses exports assignment while module uses default export + * so when bundled with webpack default export works but with jest it crashes + * That's why the following ugly fix is required + */ +const PerfectScrollbarConstructor = + PerfectScrollbarNamespace.default || ((PerfectScrollbarNamespace as any) as PerfectScrollbarType); + injectGlobal`${psStyles && psStyles.toString()}`; const StyledScrollWrapper = styled.div` @@ -11,12 +19,12 @@ const StyledScrollWrapper = styled.div` `; export class PerfectScrollbar extends React.Component<{ - options?: PerfectScrollbarConstructor.Options; + options?: PerfectScrollbarType.Options; className?: string; updateFn: (fn) => void; }> { private _container: HTMLElement; - private inst: PerfectScrollbarConstructor; + private inst: PerfectScrollbarType; componentDidMount() { this.inst = new PerfectScrollbarConstructor(this._container, this.props.options || {});