我有一个Category组件,可以从位置状态获取其状态
export class CategoryView extends React.Component {
constructor(props) {
super(props);
this.state = this.props.location.state || {}
}
...
发布索引/视图中与此链接的链接是
<Link role="post-category-link" to={
{
pathname: "categories/show/" +post.category_id,
state: {
category: category || {}
}
}
}>
{category.title }</Link>
类别是实例化的类别实例。 我想测试链接“ 至”属性的选项中的状态是否填充了预定的类别。我该如何使用Jest,Jest Dom,React Testing Library和React Test Renderer做到这一点? package.json中的相关版本:
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-router-dom": "^4.2.2"
"jest": "^24.1.0",
"jest-dom": "^3.1.2",
"react-test-renderer": "^16.8.1",
"react-testing-library": "^5.8.0",