我的组件有:
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'
我如何解决这个问题或如何在我的测试中设置查询参数?