Encountering a failure in jest unit-tests when using the defaultRowRenderer method in react-virtualized for a Table component, with the error message:
...node_modules\react-virtualized\dist\es\Table\index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import createMultiSort from './createMultiSort';
This issue can be easily replicated through the following steps:
- Start by installing a typescript app using create-react-app
- Then, install react-virtualized and @types/react-virtualized
Integrate a simple Table component in App.tsx
import * as React from "react"; import { Column, Index, Table } from "react-virtualized"; import { defaultRowRenderer } from "react-virtualized/dist/es/Table"; import "./App.css"; import logo from "./logo.svg"; class App extends React.Component { public render() { return ( <div className="App"> <header className="App-header"> <img src={logo} className="App-logo" alt="logo" /> <h1 className="App-title">Welcome to React</h1> </header> <p className="App-intro"> To get started, edit <code>src/App.tsx</code> and save to reload. </p> <Table style={{ outline: "none" }} height={300} width={300} headerHeight={40} rowHeight={40} rowCount={10} rowGetter={this.rowGetter} rowRenderer={this.rowRenderer} > <Column width={150} minWidth={90} label="Type" dataKey="Type" /> </Table> </div> ); } private rowGetter = (props: Index) => { return {}; }; private rowRenderer = (props: any) => { return defaultRowRenderer({ ...props, style: { ...props.style, outline: "none" } }); }; } export default App;
Run the unit tests
Is there a reliable solution to fix this issue?