Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 模拟酶中的history.back()_Javascript_Jestjs_Enzyme - Fatal编程技术网

Javascript 模拟酶中的history.back()

Javascript 模拟酶中的history.back(),javascript,jestjs,enzyme,Javascript,Jestjs,Enzyme,对于react组件测试,我需要模拟浏览器。对于安装的部件,这是否可行 我所尝试的: it('triggers onpopstate events',()=>{ requiredProps.filterBlocks=mockData.filterBlocks; const wrapper=mount(); global.window.history.pushState({mock:'mock'},“mock”,“mock.html”); global.window.history.pushStat

对于react组件测试,我需要模拟浏览器。对于安装的部件,这是否可行

我所尝试的:

it('triggers onpopstate events',()=>{
requiredProps.filterBlocks=mockData.filterBlocks;
const wrapper=mount();
global.window.history.pushState({mock:'mock'},“mock”,“mock.html”);
global.window.history.pushState({mock:'MOCK2'},“mock”,“MOCK2.html”);
global.window.history.back();
expect(mockedFunction).toHaveBeenCalled();
})
在组件(componentDidMount)内部,我有一个window.onpopstate侦听器:

window.onpopstate=event=>{
console.log('event',event);
};

但不会将任何内容记录到控制台。

对于我的测试,我在PopState上手动触发了:

const testEvent = { target: "mock" };

global.window.onpopstate(testEvent);