这是我试图测试的组件内的方法,但得到此错误:{TypeError:无法读取未定义的属性'push‘}
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
});
}
发布于 2017-09-27 15:58:16
您必须使用prop history
模拟组件
const history = []
const wrapper = shallow(<YourComponent history={history} />
然后,您可以像这样测试history
对象:
expect(history).toHaveLength(1)
https://stackoverflow.com/questions/46452112
复制