当我使用defaultRowRenderer(表的反应虚拟化方法)时,开玩笑的单元测试失败并出现错误:
...node_modules\react-virtualized\dist\es\Table\index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import createMultiSort from './createMultiSort';
它可以很容易地复制。脚步:
- 使用create-react-app安装typescript应用程序
- 安装react-virtualized和@types/react-virtualized
在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;
运行测试
有没有真正的方法来解决这个问题?