小编Ice*_*gth的帖子

使用Jest&Enzyme进行测试时设置URL参数

我的组件有:

 class Search extends Component {
  constructor(props) {
    super(props);
    this.state = {
      searchTerm:
        typeof this.props.match.params.searchTerm !== "undefined"
          ? this.props.match.params.searchTerm
          : ""
    };
  }
Run Code Online (Sandbox Code Playgroud)

测试是:

 test("Search should render correct amount of shows", () => {
  const component = shallow(<Search shows={preload.shows} />);
  expect(component.find(ShowCard).length).toEqual(preload.shows.length);
});
Run Code Online (Sandbox Code Playgroud)

我明白了

TypeError:无法读取undefined的属性'params'

我如何解决这个问题或如何在我的测试中设置查询参数?

reactjs jest enzyme

4
推荐指数
2
解决办法
4313
查看次数

标签 统计

enzyme ×1

jest ×1

reactjs ×1