0

我正在尝试使用createfromreact-test-renderer来渲染组件。这就是我想要做的

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 |   };

为什么?我错过了什么?

4

1 回答 1

1

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

于 2021-02-12T20:22:00.903 回答