尝试呈现用于测试的反应组件时出错

Error while trying to render a react component for tests

我正在尝试使用 react-test-renderer 中的 create 来呈现组件。这就是我想要做的

import { ReactTestRenderer, create} from 'react-test-renderer';
let component: ReactTestRenderer;
const createComponent = (tradingBalances: IBalance[]) => {
  component = create(<StakingContainer tradingBalances={tradingBalances} vaultBalances={mockVaultBalances} prices={mockPrices} />);
};

但是我一直收到这个错误:

SyntaxError: .../path/... Unexpected token, expected "," (31:41)

  29 |   let instance: ReactTestInstance;
  30 |   const createComponent = (tradingBalances: IBalance[]) => {
> 31 |     component = create(<StakingContainer tradingBalances={tradingBalances} vaultBalances={mockVaultBalances} prices={mockPrices} />);
     |                                          ^
  32 |   };

为什么?我错过了什么?

TypeScript 编译器无法识别 React 语法 (JSX)。 确保您的文件名使用 .tsx 扩展名。