Javascript componentWIllMount()使用window.location.hash值,但如何在jest中测试时提供此值
在下面的componentWillMount func中,我使用的是window.location.hash,所以我在jest中测试时如何提供这个值Javascript componentWIllMount()使用window.location.hash值,但如何在jest中测试时提供此值,javascript,reactjs,jestjs,enzyme,Javascript,Reactjs,Jestjs,Enzyme,在下面的componentWillMount func中,我使用的是window.location.hash,所以我在jest中测试时如何提供这个值 componentWillMount(){ 日志(“组件将挂载”) const{getframeworkdatabypath}=this.props; 让location=window.location.hash; log(“window.locaton散列”,window.location.hash); 控制台日志(“位置”,位置); 位置=位
componentWillMount(){
日志(“组件将挂载”)
const{getframeworkdatabypath}=this.props;
让location=window.location.hash;
log(“window.locaton散列”,window.location.hash);
控制台日志(“位置”,位置);
位置=位置。替换(“#”,”);
var数据位置={
键入:“catalogCurrentPageURL”,
价值:位置,
};
日志(“存储和常量”,存储,常量);
让dispathreturn=Store.dispatch({
类型:constants.CATALOG\u CURRENT\u PAGE\u URL,
参数:数据位置
})
log(“dispathreturn”,dispathreturn)
getframeworkdatabypath(位置);
}
可能会开玩笑地尝试设置窗口对象的值?但是,我的建议是用一个函数调用替换它,比如说getUrl
,然后欺骗该函数并返回伪URL。或者,作为参数传入hash
?