首页 > 解决方案 > 如何在反应中测试url查询字符串

问题描述

如何从下面的代码片段测试 this.props.location.search。

我收到以下错误:TypeError:无法读取未定义的属性“搜索”

export class myView extends React.Component {
    componentDidMount() {
        const values = queryString.parse(this.props.location.search);
}
});

我想测试变量值中存在的值。

标签: reactjsjestjs

解决方案


我使用了@Praveen Rao Chavan.G 的建议,https: //medium.com/@matthew.holman/testing-url-hash-query-with-jest-8165f26ab94e链接帮助解决了这个问题。


推荐阅读