首页 > 解决方案 > 单元测试时如何通过{history, location, match}

问题描述

我正在针对以下组件运行测试:

const App: React.FC<RouteComponentProps> = ({ history, location, match }) => { ... }

所有的测试都通过了,但是我收到了这个警告:

const { getByText, debug } = render(<MemoryRouter><Route><App/></Route></MemoryRouter>);

Type '{}' is missing the following properties from type 'RouteComponentProps<{}, StaticContext, {}>': history, location, match(2739)

我的印象是<MemoryRouter>&<Route>会提供<App/>缺失的属性......

标签: reactjstypescriptreact-router-domreact-testing-library

解决方案


推荐阅读