mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-25 18:13:44 +03:00
tests: workaround perfectscroll importing issue in jest
This commit is contained in:
parent
83af48112c
commit
29a7f299a1
|
@ -1,9 +1,17 @@
|
||||||
import * as React from 'react';
|
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 psStyles from 'perfect-scrollbar/css/perfect-scrollbar.css';
|
||||||
import styled, { injectGlobal } from '../styled-components';
|
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()}`;
|
injectGlobal`${psStyles && psStyles.toString()}`;
|
||||||
|
|
||||||
const StyledScrollWrapper = styled.div`
|
const StyledScrollWrapper = styled.div`
|
||||||
|
@ -11,12 +19,12 @@ const StyledScrollWrapper = styled.div`
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export class PerfectScrollbar extends React.Component<{
|
export class PerfectScrollbar extends React.Component<{
|
||||||
options?: PerfectScrollbarConstructor.Options;
|
options?: PerfectScrollbarType.Options;
|
||||||
className?: string;
|
className?: string;
|
||||||
updateFn: (fn) => void;
|
updateFn: (fn) => void;
|
||||||
}> {
|
}> {
|
||||||
private _container: HTMLElement;
|
private _container: HTMLElement;
|
||||||
private inst: PerfectScrollbarConstructor;
|
private inst: PerfectScrollbarType;
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.inst = new PerfectScrollbarConstructor(this._container, this.props.options || {});
|
this.inst = new PerfectScrollbarConstructor(this._container, this.props.options || {});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user