Skip to content

Commit

Permalink
tests: workaround perfectscroll importing issue in jest
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Mar 26, 2018
1 parent 83af481 commit 29a7f29
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/common-elements/perfect-scrollbar.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
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`
position: relative;
`;

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 || {});
Expand Down

0 comments on commit 29a7f29

Please sign in to comment.