如何在重定向之前修改URI实例import MyModalComponent from '../components/my-modal-component'
import React from 'react'
import { jsdom } from 'jsdom'
import { mount } from 'enzyme'
describe('<MyModalComponent /> Component', function(){
let wrapper
beforeEach(function(){
window.document = jsdom('')
document.body.appendChild(document.createElement('div'))
})
afterEach(function(){
wrapper.detach()
window.document = jsdom('')
})
it('renders the modal closed by default', () => {
wrapper = mount(
<MyModalComponent prop1={"foo"}
prop2={"bar"}
/>, { attachTo: document.body.firstChild }
)
expect(wrapper.html()).to.contain('Content in component')
expect(document.body.innerHTML).to.not.contain('Content in overlay')
})
})
,尤其是查询部分?
我试图添加一个修改请求的中间件,但是一旦我添加var alphabet = "abcdefghijklmnopqrstuvwxyz"
for (var i=0;i<alphabet.length;i++) {
var news = "";
news = news + alphabet[Math.floor(Math.random() * alphabet.length)]
if (i == alphabet.length - 1) {
console.log(news)
}
}
,响应主体总是返回一个空字符串。
GuzzleHttp\Psr7\Uri
答案 0 :(得分:0)
问题是由于HandlerStack类型,CurlHandler默认不处理重定向。
如何修改请求URI
$stack = HandlerStack::create();
$stack->push(Middleware::mapRequest(function (RequestInterface $request) {
// Retrieve the URI
$uri = $request->getUri();
$query = // update query
// Update the URI query
$uri = $uri->withQuery($query);
return $request->withUri($uri);
}));