Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.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 测试中的模拟获取重定向_Javascript_Unit Testing_Redirect_Fetch_Sinon - Fatal编程技术网

Javascript 测试中的模拟获取重定向

Javascript 测试中的模拟获取重定向,javascript,unit-testing,redirect,fetch,sinon,Javascript,Unit Testing,Redirect,Fetch,Sinon,我正在尝试测试使用fetch API执行重定向请求后的行为 我一直在使用sinon模拟窗口。获取并让它返回所需的响应。以下是我所做的,简化: windowFetch = sinon.stub(window, 'fetch'); windowFetch.withArgs('http://example.com/resource') .returns(Promise.resolve(new Response(body, { status: 200

我正在尝试测试使用fetch API执行重定向请求后的行为

我一直在使用sinon模拟
窗口。获取
并让它返回所需的响应。以下是我所做的,简化:

windowFetch = sinon.stub(window, 'fetch');

windowFetch.withArgs('http://example.com/resource')
           .returns(Promise.resolve(new Response(body, {
               status: 200,
               headers: new Headers(headers)
           })));
这适用于标准响应。要处理重定向,我想访问
Response#url
属性,但我还没有找到在单元测试中设置它的方法

无法使用
new Response()
构造函数设置它,而且它是只读的,所以我也不能这样做

最后,我尝试调用
Response.redirect(toAddr)
,但它创建了重定向响应和随后的响应。浏览器透明返回的一个