这是我尝试测试的组件内部的方法,但是我收到此错误:{TypeError:无法读取属性'push'of undefined}
setQuery(newQueryElement)
//merge together the current query with the new query element
var currentQuery = QueryString.parse(this.state.currentProjectQuery);
Object.assign(currentQuery, newQueryElement);
//now turn the query into a query string and navigate to it
var queryString = QueryString.stringify(currentQuery);
this.props.history.push({
pathname: this.props.location.pathname,
search: "?" + queryString
});
}
答案 0 :(得分:0)
您必须使用道具history
模拟您的组件:
const history = []
const wrapper = shallow(<YourComponent history={history} />
然后你可以像这样测试你的history
对象:
expect(history).toHaveLength(1)